Introduction
In this article, you will see how to enable or disable a checkbox in GridView records based on the condition.
RowDataBound Event
A GridviewRowEventArgs object is passed to the event-handling method, that enables you to access the properties of the row being bound. To access a specific cell in the row, use the "cell" property of the GridViewRow object contained in the Row property of the GridEventRowEventArgs object.
Now let's have a look at this web application to see how to use the RowDataBound Event.
Step 1
Open Visual Studio then select "File" -> "New" -> "Website..." as in the following figure:

Step 2
Now go to the Solution Explorer and add a new item as in the following figure:

Step 3
Now add a new web form on your web application as in the following figure:

Step 4
Write the following code in the "default.aspx" page:
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Enable/Disable Checkbox in Gridview based on condtion in ASP.Net</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:GridView ID="gvDetails" AutoGenerateColumns="False" CellPadding="3" runat="server"
- OnRowDataBound="gvDetails_RowDataBound" BackColor="White"
- BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" ForeColor="Black" GridLines="Vertical">
- <AlternatingRowStyle BackColor="#CCCCCC" />
- <Columns>
- <asp:TemplateField>
- <ItemTemplate>
- <asp:CheckBox ID="chkSelect" runat="server" />
- </ItemTemplate>
- </asp:TemplateField>
- <asp:BoundField HeaderText="UserId" DataField="UserId" />
- <asp:BoundField HeaderText="UserName" DataField="UserName" />
- <asp:BoundField HeaderText="Education" DataField="Education" />
- <asp:BoundField HeaderText="Location" DataField="Location" />
- </Columns>
- <FooterStyle BackColor="#CCCCCC" />
- <HeaderStyle BackColor="Black" Font-Bold="true" ForeColor="White" />
- <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
- <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
- <SortedAscendingCellStyle BackColor="#F1F1F1" />
- <SortedAscendingHeaderStyle BackColor="#808080" />
- <SortedDescendingCellStyle BackColor="#CAC9C9" />
- <SortedDescendingHeaderStyle BackColor="#383838" />
- </asp:GridView>
- </div>
- </form>
- </body>
- </html>
Add the connectionstring in web.config file such like :
- <connectionStrings>
- <add name="dbconnection" connectionString="Data Source=; Initial Catalog=Employee;
- User=abc; Password=***" providerName="SqlClient"/>
- </connectionStrings>
Step 5
Now write the following code in the "default.aspx.cs" page:



Mg KyaingPosted Jul 6, 2014, 2:56 PM
Thank you it is good for my project.
pankaj sengarPosted Feb 19, 2014, 11:58 AM
its good....