VS2010 .net
I have a gridview that displays information from a database. One of the fields is a checkbox. What I would like to do is be able to click the checkbox and have it update back to the database, but the checkbox field is grayed-out. Below is my markup. searching for making checkboxes clickable does not return any helpful results.
<asp:GridView ID="gvSiteInfo" runat="server" BackColor="White"
GridLines="Vertical" AutoGenerateColumns="False" OnSorting="gvSiteInfo_Sorting"
onselectedindexchanged="gvSiteInfo_SelectedIndexChanged"
AllowSorting="True">
<Columns>
<asp:BoundField DataField="prodServer" HeaderText="Production Server"
SortExpression="prodServer" />
<asp:BoundField DataField="prodHostHeader" HeaderText="Production Host Header"
SortExpression="prodHostHeader" />
<asp:BoundField DataField="prodIP" HeaderText="Production IP Address"
SortExpression="prodIP" />
<asp:CheckBoxField DataField="testComplete" HeaderText="Testing Completed"
SortExpression="testComplete" />
</Columns>
</asp:GridView>
You should use a templatefield
:
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelector" runat="server"
ToolTip="Select row?" />
</ItemTemplate>
</asp:TemplateField>
You also do not seem to set the value based on the database:
Checked='<%# DataBinder.Eval(Container, "DataItem.IsChecked") %>'