[RESOLVED] [2005] Which event to use in GridView?
Hi!
I have a problem with the GridView
When I put a row in edit mode by pressing the "Edit" button, in one of the templatecolumns I have a dropdownlist. If the source data returned to this dropdown is null (Its a list of contacts, and no contacts have been added), I need to add a row to this dropdown with text="No contacts available..." and value = -1, because -1 is returned from the Bind() of the gridview.
Which event should I use to check the datasource for the edit dropdown? If the rows in teh datasource is 0 then I want to add this "dummy" row. But I need to do it before the grid is trying to bind, and after the data has been bound to the dropdown...
This works great with the footer, when I hade the add item functonality. But there, the dropdown exist all the time... The edit dropdown exist only after the edit postback.
Here is the code for the edit dropdown:
Code:
<EditItemTemplate>
<asp:DropDownList ID="ddlEditVendorContact"
runat="server"
CssClass="text"
DataSource='<%# GetVendorContacts() %>'
DataTextField="contact_name"
DataValueField="vendor_contact_id"
SelectedValue='<%# Bind("vendor_contact_id") %>'>
</asp:DropDownList>
</EditItemTemplate>
Basically, if the GetVendorContacts() return table with 0 rows I need to add a dummy record BEFORE the SelectedValue='<%# Bind("vendor_contact_id") %>' occurs.
Is this at all possible?
kind regards
Henrik
Re: [2005] Which event to use in GridView?
are you saying that the dropdown's databound event does not fire? as this is where i would perform this action
Re: [2005] Which event to use in GridView?
Use the GridView's RowEditing event. You will need to do a FindControl() to get a reference to the dropdownlist, which you should then cast, and add the row to.
Re: [2005] Which event to use in GridView?
Thanks for the suggestions, its working now!
/Henrik