What is the difference between RowIndex and DataItemIndex?

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

+6
source share
4 answers

Use the DataItemIndex property to determine the DataItem index in the underlying DataSet.
Use the RowIndex property to determine the index of the GridViewRow in the Rows collection of the GridView control.

+6
source

e.Row.RowIndex return the index of the row that is currently under mandatory

e.Row.DataItemIndex contains all the row data indexes that are currently under the binding.

+4
source

DataItemIndex is the DataItem index in the underlying DataSet. YES

RowIndex is the Row row index in the underlying GridView. YES

But there is a big difference

For example, if your girdview has a page size of 10 lines, your RowIndex will always be 0-9 for each page, but DataItemIndex will be different when you go to other pages, such as PageIndex 2,3,4 ... On page 2 DataItemIndex will be between 10-19, but RowIndex is still 0-9.

+3
source

Well, the difference may be that "e.Row.DataItemIndex" applies only to the DataItem; means This property applies only to data lines, where "e.Row.RowIndex" can be for datarow, header lines, etc.

RowIndex is the current visible row in the displayed table. DataItemIndex is the actual index of the element; they will both show the record index in the set of records currently being displayed.

+2
source

Source: https://habr.com/ru/post/888332/


All Articles