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.