Unplanned
Last Updated: 12 Nov 2020 15:57 by ADMIN
Jozef
Created on: 12 Nov 2020 15:48
Category: Grid
Type: Bug Report
0
e.Item contains Incorrect item in the GridCommandEventArgs
Regardless of which item is being clicked on, the e.Item will always be the first from the list.
1 comment
ADMIN
Attila Antal
Posted on: 12 Nov 2020 15:57

Thank you for reporting this problem.

After our investigation on this issue, we found that the Grid will use the first item on the list to fire a GridCommand if either the OnCommand or OnUserAction client-side events are attached.

Until the issue is fixed, please use the "e.CommandArgument" property to access the correct item index, then use that index to access the correct GridItem from the Items collection.

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "MyCommand")
    {
        // e.Item.ItemIndex = 0 // wrong index
        // e.CommandArgument = "9" // correct index

        // Correct ItemIndex
        int itemIndex = int.Parse(e.CommandArgument.ToString());

        // access item by the correct itemIndex
        var dataItem = (sender as RadGrid).Items[itemIndex];
        // get the data key value of the correct item
        var orderId = dataItem.GetDataKeyValue("OrderID");
    }
}