Sreedhar Danturthi
Sreedhar Danturthi

Reputation: 7571

Query regarding rowdatabound event in gridview asp.net/C#

When u have a gridview(lets say gridview1) and u associate an event

OnRowDataBound = "gridView1_RowDatabound"

and u usually start the event method as follows

protected void gridView1_RowDatabound(object sender, GridViewRowEventArgs e){

      if (e.Row.RowType == DataControlRowType.DataRow){
        do something..
      }

      }

Why do u have to check again if the row is data row, as i understand it gridview1_rowdatabound event occurs only when the rows are getting bound by the datasource u supplied. Why do u perform again this additional checking ?

Can u elucidate it for me ?

Thanks in anticipation

Upvotes: 0

Views: 2047

Answers (1)

ntziolis
ntziolis

Reputation: 10221

This is to be able to perform different actions based on the row type:

A row can be a 'header' row or a normal 'data' row for example.

The DataControlRowType enum gives you a pretty good idea what types of rows might appear:

public enum DataControlRowType
{
    Header,
    Footer,
    DataRow,
    Separator,
    Pager,
    EmptyDataRow
}

Upvotes: 2

Related Questions