RowDataBound Event of GridView

By Sandeep Singh Shekhawat Feb 14, 2013
In this blog I explain RowDataBound Event of GridView Control.

The RowDataBound event occurs when a data row is bound to data in a GridView control. This event is raised a data row means GridViewRow object is bound to data in GridView control.

By help of this event we can modify row appearance or can modify data in data row at time of GridViewRow object bounds.

A RowDataBound event of gridview has two arguments one is object and another is GridViewRowEventArgs. GridViewRowEvnetArgs object enables us to access the properties of row that is bounding because  GridViewRowEventArgs object has Row property.


Design Of Gridview and DataSource

<asp:GridView ID="gvCustomres" runat="server"






            Width=40% onrowdatabound="gvCustomres_RowDataBound">


                <asp:TemplateField HeaderText="S.No." ItemStyle-HorizontalAlign="Center">





                <asp:BoundField DataField="Name" HeaderText="Employee Name" />

                <asp:BoundField DataField="Emp_Code" HeaderText="Employee Code" />

                <asp:BoundField DataField="Emp_Age" HeaderText="Employee Age" />               




       <asp:SqlDataSource ID="EmployeeDataSource" runat="server"

        ConnectionString="Data Source=sandeepss-PC; database=development; user=sa;password=knowdev"

         SelectCommand="select Id, Name, Emp_Code,Emp_Age from EMPLOYEE">



RowDataBound Event

Here we are showing row background color blue these have age value greater than or equal 35.

protected void gvCustomres_RowDataBound(object sender, GridViewRowEventArgs e)


            if (e.Row.RowType == DataControlRowType.DataRow)


                int age =Convert.ToInt32( e.Row.Cells[3].Text);

                if (age >= 35)


                    e.Row.BackColor =System.Drawing.ColorTranslator.FromHtml("#4F81BD");

                    e.Row.ForeColor =System.Drawing.ColorTranslator.FromHtml("#FFFFFF");






Sandeep Singh Shekhawat
Sandeep Singh Shekhawat

Sandeep Singh Shekhawat is a Software Developer. He is awarded for C# Corner MVP(2013,2014 and 2015) and CodeProject MVP (2015). His three articles at CodeProject are prize wining in article competition. His more than 10... Read more