TemplateColumn:DropDownList Edit Selected Item
-
I've hit a wall. I'm working with a web-based DataGrid, using Template Columns bound to a dataset. Once column contains a text box for the Item template and DropDownList for the Edit Template. The Dropdowns are populated from a DataTable within the DataSet being used. Everything displays properly (i.e. the DDL contains all of the expected values), but upon entering the "edit mode" for a row, the DropDownList is always set to the FIRST entry! How can I get the DDL to select the correct value? Not sure if this will make it more or less clear...:wtf:
<asp:TemplateColumn HeaderText='Company Name'> <ItemTemplate> <asp:Label id=Label3 runat='server' Text='<%# DataBinder.Eval(Container,'DataItem.CompanyName') %>'> </asp:Label> </ItemTemplate> <FooterTemplate> <asp:dropdownlist DataSource='<%# GetCompanies() %>' DataTextField='Name' DataValueField='CompanyID' runat='server' ID='cmbFooterCompanyID'> </asp:dropdownlist> </FooterTemplate> <EditItemTemplate> <asp:dropdownlist DataSource='<%# GetCompanies() %>' DataTextField='Name' DataValueField='CompanyID' runat='server' ID='cmbEditCompanyID'> </asp:dropdownlist> </EditItemTemplate> </asp:TemplateColumn>
Thanks. Mike Stanbrook mstanbrook@yahoo.com -
I've hit a wall. I'm working with a web-based DataGrid, using Template Columns bound to a dataset. Once column contains a text box for the Item template and DropDownList for the Edit Template. The Dropdowns are populated from a DataTable within the DataSet being used. Everything displays properly (i.e. the DDL contains all of the expected values), but upon entering the "edit mode" for a row, the DropDownList is always set to the FIRST entry! How can I get the DDL to select the correct value? Not sure if this will make it more or less clear...:wtf:
<asp:TemplateColumn HeaderText='Company Name'> <ItemTemplate> <asp:Label id=Label3 runat='server' Text='<%# DataBinder.Eval(Container,'DataItem.CompanyName') %>'> </asp:Label> </ItemTemplate> <FooterTemplate> <asp:dropdownlist DataSource='<%# GetCompanies() %>' DataTextField='Name' DataValueField='CompanyID' runat='server' ID='cmbFooterCompanyID'> </asp:dropdownlist> </FooterTemplate> <EditItemTemplate> <asp:dropdownlist DataSource='<%# GetCompanies() %>' DataTextField='Name' DataValueField='CompanyID' runat='server' ID='cmbEditCompanyID'> </asp:dropdownlist> </EditItemTemplate> </asp:TemplateColumn>
Thanks. Mike Stanbrook mstanbrook@yahoo.comYou need to set the selectedindex property of the dropdownlist. Todd Smith
-
You need to set the selectedindex property of the dropdownlist. Todd Smith
Todd Smith wrote: You need to set the selectedindex property of the dropdownlist. I've tried, but I'm not sure WHERE or WHEN (in the page lifecycle) that should be set. Also, I am not clean on how to get the index from the Dataset/DataTable where the values are stored. Mike Stanbrook mstanbrook@yahoo.com