I would like to display the field in my GridView as a DropDownList when the user edits a row. DropDownList will be pre-populated with two values: โYesโ and โNoโ, and depending on what value the user selects, I would like to set a variable.
Example:
I have a field called active. 1 = active, 0 = inactive. Although for the user, I would like them to either set Active as โYesโ (1) or โNoโ (0). When, when editing a line, they could either select โYesโ or โNoโ from the drop-down list, and it will set the variable to 1 or 0, so I can send it back to the SQL update.
I found this MSDN article .
but it only tells me how to populate a DropDownList from a DataSource, which will not work for me, since each field has either yes or no for the active. It also displays a drop, even with a simple view of the GridView, and not just when editing.
I hope this makes sense, thanks for the help.
EDIT
Here is the code that I have now, it almost works as I would like. All I have to do is change the label text to โYesโ if the Active value is โTrueโ and change the text to โNoโ if the Active value is โFalseโ.
<asp:TemplateField HeaderText="Active" SortExpression="Active" >
<ItemTemplate>
<asp:Label ID="lblActive" runat="server" text='<%# Eval("Active") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("Active") %>'>
<asp:ListItem Text="Yes" Value="True"></asp:ListItem>
<asp:ListItem Text="No" Value="False"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
source
share