JeffDrummond
asked on
Finding control in datagrid EditItemTemplate
In my C# ASP.Net application, I have a datagrid with item and edititem
templates. On my datagrid Edit Command, I am unable to find a dropdownlist
control in the edititemtemplate. Please take a look and let me know what I am
doing wrong! Thanks.
Code-behind
===========
private void dgRooms_EditCommand(object source, System.Web.UI.WebControls. DataGridCo mmandEvent Args e)
{
try
{
//set the edit item index
dgRooms.EditItemIndex = e.Item.ItemIndex;
//fill the drop down lists, one-by-one
//fill the dataset
this.RoomSettingsAdapter.F ill(RoomsD ataset);
//create a filter string
string filter;
//room location
DropDownList ddl1 = (DropDownList)e.Item.FindC ontrol("dd lEditRoomL ocation"); <==DOES NOT FIND DROPDOWN HERE
filter ="SettingType = " + 8;
ddl1.DataSource = this.RoomsDataset.Settings .Select(fi lter);
ddl1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message) ;
}
}
HTML CODE
====================
<asp:TemplateColumn HeaderText="Location">
<ItemTemplate>
<asp:Label id="Label27" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LocationDescript ion") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlEditRoomLocation" runat="server" DataTextField="Setting" DataValueField="SettingsId S"> </asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
templates. On my datagrid Edit Command, I am unable to find a dropdownlist
control in the edititemtemplate. Please take a look and let me know what I am
doing wrong! Thanks.
Code-behind
===========
private void dgRooms_EditCommand(object
{
try
{
//set the edit item index
dgRooms.EditItemIndex = e.Item.ItemIndex;
//fill the drop down lists, one-by-one
//fill the dataset
this.RoomSettingsAdapter.F
//create a filter string
string filter;
//room location
DropDownList ddl1 = (DropDownList)e.Item.FindC
filter ="SettingType = " + 8;
ddl1.DataSource = this.RoomsDataset.Settings
ddl1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message)
}
}
HTML CODE
====================
<asp:TemplateColumn HeaderText="Location">
<ItemTemplate>
<asp:Label id="Label27" runat="server" Text='<%# DataBinder.Eval(Container,
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlEditRoomLocation" runat="server" DataTextField="Setting" DataValueField="SettingsId
</EditItemTemplate>
</asp:TemplateColumn>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks faifai. It does work in ItemDataBound.
I still do not know why I could not find the control in the EditCommand?!?!
I still do not know why I could not find the control in the EditCommand?!?!
you may try to add some breakpoint in edit command, itemdatabound_command and page load, u will know which event will process first.
filter ="SettingType = " + 8;
DropDownList ddl1= (DropDownList)e.Item.Cells
ddl1.DataSource = this.RoomsDataset.Settings
ddl1.DataBind();
Thanks