Eval() in a DropDownList within a GridView
18,269
Solution 1
Try this way
<asp:DropDownList ID="ddlPrioridade" runat="server" AppendDataBoundItems="true" DataSourceID="datasource" DataTextField="key" DataValueField="data" AutoPostBack="True" SelectedValue='<%# Eval("Prioridade") %>'>
also have a look at this DropDownList inside a GridView (or DataGrid). It might help you
Solution 2
You are receiving this error because the drop down list is not loaded with items and asp.net is trying to set the selected value of an empty drop down list and that's why it gives you error. So fill the drop down list first before setting it's selected value.
Comments
-
Lucas_Santos almost 2 years
How can I do
Eval()
in aDropDownList
that are inside aGridView
?I tried the follow code, but still wrong:
<asp:TemplateField HeaderText="Prioridade"> <ItemTemplate> <asp:DropDownList ID="ddlPrioridade" runat="server" SelectedValue='<%# Eval("Prioridade") %>'> </asp:DropDownList> </ItemTemplate> </asp:TemplateField>
-
Lucas_Santos over 12 yearsBut, this is a DropDownList with Priorities. This will be loaded with the GridView. With this code, will appear just the actual Priority status, and if I wanna change de Priority status, how can I do to fill my dropdownlist with more status option different than the actual status ?
-
huMpty duMpty over 12 yearsThen just add the dropdown and in the GridviewRowDataBound event you can fond the dropdown which accociate with each row and fill the dropdown with data source