Showing Yes or No instead of 1 or 0 in GridView |
You don't have to have another sqldatasource to bind a yes or a no. Try this solution and let me know if this works for you.
<asp:TemplateField HeaderText="YOUR_FIELD" SortExpression="YOUR_FIELD">
<EditItemTemplate>
<asp:DropDownList ID="dropYesNo" runat="server" SelectedValue='<%# Bind("YOUR_FIELD") %>' >
<asp:ListItem Value="0">No</asp:ListItem>
<asp:ListItem Value="1">Yes</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<%#Eval("YOUR_FIELD").ToString() == "1" ? "Yes" : "No" %>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
Of course, the field that you want needs to be converted to a TEMPLATE FIELD. Let me know if you don't know how to do that and I'll help or post how to.
Yes or No binds from DropDown |
I use
<%#Eval("YOUR_FIELD").ToString() == "1" ? "Yes" : "No" %>
the EVAL to test if the field is 1 or 0 to show Yes or No in the gridview. I put this in the ItemTemplate.
Also notice,
<asp:ListItem Value="0">No</asp:ListItem>
<asp:ListItem Value="1">Yes</asp:ListItem>
So that your 0 and 1 are written back to your table when you click update.
Happy Coding... :)