Reputation: 22086
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?
Upvotes: 10
Views: 7894
Reputation: 4127
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.
Upvotes: 3
Reputation: 77926
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.
Upvotes: 2
Reputation: 52241
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.
Upvotes: 4
Reputation: 22086
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.
Upvotes: 8