In gridview’s
RowDataBound
event has e.Row.RowIndex
and e.Row.DataItemIndex
properties.
Please tell me in easily understandable answer, what is difference between them?
In which situation we should use which one?

- 21,570
- 27
- 74
- 94
4 Answers
Use the DataItemIndex
property to determine the index of the DataItem in the underlying DataSet.
Use the RowIndex
property to determine the index of the GridViewRow object in the Rows collection of a GridView control.

- 21,570
- 27
- 74
- 94
-
For a particular row in the girdview the value of both these will be same or different? – Amit May 17 '11 at 15:36
-
1Don't get confused `DataItemIndex` is the property of `DataSet` and `RowIndex` is the property of Giridview. – Amit May 17 '11 at 16:10
-
2They are different if you use paging. Then `DataItemIndex` will return index from the beginning of first page and `RowIndex` will give you index on that specific page. This is very important if you want to use data item in `RowCommand` event. – Episodex May 10 '12 at 14:31
e.Row.RowIndex
return the index of the row that is currently under binding
e.Row.DataItemIndex
contains all the data indexes of the rows that is currently under binding.

- 51,913
- 37
- 138
- 191
-
For a particular row in the girdview the value of both these will be same or different? – Amit May 17 '11 at 15:36
-
They may have different index. You just need to understand the logic of how and where which can be used. – Muhammad Akhtar May 17 '11 at 15:44
DataItemIndex is the index of DataItem in the underlying DataSet. YES
RowIndex is the index of Row in the underlying GridView. YES
But there is big a difference
e.g If your girdview has the page size of 10 rows then your RowIndex is always 0-9 for each page but the DataItemIndex will be different when you will go for other pages such as PageIndex 2,3,4 ... On page 2 the DataItemIndex will be between 10-19 but the RowIndex is still 0-9.

- 4,079
- 2
- 33
- 25
Well the difference could be that "e.Row.DataItemIndex" applies to DataItem only; means This property applies only to data rows where as "e.Row.RowIndex" could be for datarow, header row, etc.
RowIndex is the current visible row in the rendered table. DataItemIndex is the actual item's index; they both will show the index of the record in the set of currently displayed records.

- 76,197
- 13
- 71
- 125
-
For a particular row in the girdview the value of both these will be same or different? – Amit May 17 '11 at 15:36