This is a migrated thread and some comments may be shown as answers.

Datasource item index in ItemCommand

1 Answer 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TonyG
Top achievements
Rank 1
TonyG asked on 21 Jan 2014, 04:06 AM
I have a grid with a LinkButton which triggers an ItemCommand event. When the grid is ungrouped and unsorted the e.Item.ItemIndex provides the correct value. But when grouped or sorted, ItemIndex is incorrect. I've also tried DataSetIndex and RowIndex but these don't help either. Assume the datatable used to populate the grid has 30 rows and row 29 has the data of interest. Group and Sort the grid and let's say that data lands in the 2nd group, 3rd row, overall in row 12 in the grid

Given the tools available how do I get "29" so that I can go back to the data source and pull the row with that index?

And given the example above, what properties are available to return the other data: group 2, row 3 in group 2, row 12 in the grid.

Preferring to be taught how to fish rather than being given a fish, where should I have found all of this information? The tooltips in code seem to be inaccurate and the documentation isn't much more helpful.

I have already solved this problem by adding a new value into my data table, a UniqueID which is just the sequential in index of the order in which objects are added to the table. Then I added a new hidden column to the grid, and in ItemCommand I use that value converted to Int as an index on the table. This will probably be extended to use the an alphanumeric UniqueID, and then I'll use LINQ to select the record with that UniqueID. I'd rather not have to recall the entire dataset back into the code to do this.

Thanks

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 23 Jan 2014, 03:12 PM
Hello Tony,

This behavior is expected when grouping or sorting the grid. The reason is that the ItemIndex start from 0 and continues till the end of the rows each time when the grid is sorted/filtered/grouped/. You could examine the following help article which demonstrates how to persist the selected rows on sorting. You will notice that the approach is the same as the one which you have come up already.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
TonyG
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or