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

ItemCommand Item

2 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JedF
Top achievements
Rank 1
JedF asked on 20 Jan 2011, 02:36 PM
Hello

I have a grid that when i click on a item to edit it I try get the datakeyvalue from that item but it always just gets the first item on the list.

So i had a look in the grid.Items and found out that if i have data eg.
column1    column2
1             test1
2   test2
3   test3
4   test4

in my grid and i click on my edit button on the test3 row or whichever row then go look in the grid.items

It will change the item to the first item eg
In the grid.Items
Index    DataKeyValue
1           1
2           2
3           1(my row i click on)
4           4

Anyone ever had this any suggestions
 thanks

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Jan 2011, 09:30 AM
Hello,


Use the following code to get the DataKeyValue in ItemCommand event when clicking "Edit" l;ink.

Code:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    GridDataItem item = (GridDataItem)e.Item;
    string key = item.GetDataKeyValue("CustomerID").ToString();
    Response.Write(key);
}




-Shinu.
0
JedF
Top achievements
Rank 1
answered on 21 Jan 2011, 11:12 AM
I have used

var keyValue = ((GridEditableItem)e.Item).GetDataKeyValue(this.MasterTableView.DataKeyNames[0]);

This returns the value of the first item on the grid whatever row is clicked.
Tags
Grid
Asked by
JedF
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
JedF
Top achievements
Rank 1
Share this question
or