Click here to Skip to main content
13,086,662 members (55,611 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Why we write it in grid view row data bound?
if(e.Row.RowType == DataControlRowType.DataRow)
Posted 23-Apr-13 19:51pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi Raju,

I assume that you need to know about why we are using the below line in row data bound..?

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

If so, then follow it here.

We have different kinds of rows like Header row, Footer row, Data row, Empty Data Row, Pager and Seperator. These are the kinds of rows that we can generate in Gridview and use them as per our usage. But most of the time, we only work with the data row in order to show the data, manipulate the data, add CSS to that data row, customize the data in a row, but not for header rows and other above specified rows.

This row databound event will be called when ever we call


So, for every kind of row that you have in your gridview (that you'll specify in the designer part like ShowFooter="true", ShowHeader="true"), this event is fired. We'll have all the logic in this event and we want that to be called only for DataRow and not for all other kinds of row which will obvisouly dont go inside the if condition that you specified above.

If we dont use that condition, it'll try to run the code for other rows also, and cause errors.

Hope you got my point.! If its not what ou wanted, let me know.

Thank you,
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

It's to verify that row (row in a gridview or detailsview), is of type dataRow.

Gridview has different types of rows.
1) Header
2) DataRow
4) Pager
5) Separator.
6) EmptyDataRow

Based on what is supposed to be accessed, RowType is mentioned in RowDataBoundEvent

If you want to access footer and display calculated Total, you can write like:
private Decimal orderTotal = 0.0M;
if (row.RowType == DataControlRowType.Footer)
      // Get the Label control in the footer row.
      Label total = (Label)e.Row.FindControl("lblTotal");
      // Display the grand total of the order formatted as currency.
      if (total != null)
        total.Text = orderTotal.ToString("c");

Similarly if you want to access data inside the gridview, you can write like:
if (row.RowType == DataControlRowType.DataRow)
   //Your code changes/manipulations here.

Please go through following link for more information:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 24 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100