开发者

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

开发者 https://www.devze.com 2023-02-20 19:28 出处:网络
When u have a gridview(lets say gridview1) and u associate a开发者_如何学Gon event OnRowDataBound = \"gridView1_RowDatabound\"

When u have a gridview(lets say gridview1) and u associate a开发者_如何学Gon 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


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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号