The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
Hi,
I don''t know how to map datarow index and grid index in GridDataBoundGrid.
Ex:
- I have a datatable which have 10 rows.
- Using method "grid.DataSource=dt" to bind data.
- after that, I used "DeleteRecordsAtRowIndex" to delete 5 rows. And now, in the grid, there are 5 rows
- And in datatable still exists 10 rows( 5 rows is marked as Deleted and 5 rows is marked as Unchanged)
Please let me know how to get the position in the grid if I know the row index in datatable.
Thanks
ADAdministrator Syncfusion Team April 1, 2005 09:47 AM UTC
If you use "grid.DataSource=dt", then the grid is really bound to dt.DefaultView. You need to use the DataView, and not the Datatable, to support things like sorting and deleting. If your grid is sorted, the DataTable is no longer mapped 1 to 1 with the rows in the grid. it is the Dataview that is mapped 1-1 with the rows in the grid.
Given a position in the DataView (or more generally in the CurrencyManager.List), you can get the rowIndex in the grid using grid.Binder.PositionToRowIndex method.
Given a rowIndex in the grid, you can use grid.Binder.RowIndexToPosition to get the position in the DataView or (CurrencyManager.List).
For example, to get the DataRow object from your DataTable associated with the grid row at rowIndex, use code like:
int position = grid.Binder.RowIndexToPosition(rowIndex);
CurrencyManager cm = grid.BindingContext[grid.DataSource, grid.DataMember] as CurrencyManager;
DataView dv = cm.List as DataView;
DataRowView drv = dv[position];
DataRow dr = drv.Row;
Now if you want to find a grid rowIndex from some arbitary position in the DataTable, you muts first find where this arbitary position is in the associated DataView. If things are sorted, you can use DataView.Find or soemthing similar. If they are not, then you may have to loop through the dataview to locate the position. Once you have the position in the DataView, you can use grid.Binder.PositionToRowIndex to get teh grid row.