July 23, 2019 12:23 by
Peter
This code will help the developers to check and uncheck the gridview checkbox based on the value from the database.
Create a GridView with checkbox.
<asp:GridView ID="Gridview" runat="server" Font-Size="8pt"
PageSize="200" Width="880px" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" Text="Select All" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkChild" runat="server" Checked='<%# Eval("PROCESSED").ToString().Equals("1") %>' Enabled='<%# !Eval("PROCESSED").ToString().Equals("1") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Get the data from the database, the field from the database to check the checkbox should be 1 or 0.
DB Table data
PROCESSED (HEADER)
1
1
0
DataField "PROCESSED" should be 1 or 0 (boolean),
Checked='<%# Eval("PROCESSED").ToString().Equals("1") %>'
The above GridView code will check the checkbox if the value from the PROCESSED field in DB is 1 else if the PROCESSED value is other than 1 the checkbox will be unchecked,
Enabled='<%# !Eval("PROCESSED").ToString().Equals("1") %>'
This code will help us to enable or disable the text box. In the above mentioned code, if the PROCESSED is 1, checkbox will be disabled else the checkboc will be enable.
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.