Reputation: 57
I've spend the last few hours trying to solve this, which i imagine is a easy fix. However i haven't been able to find the solution yet.
In my grid im using:
AutoGenerateEditColumn="true"
When i press the Edit button in a row, i want to do a custom check in the RadGrid1_UpdateCommand event.
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateEditColumn="true" DataSourceID="ObjectDataSource">
<MasterTableView CommandItemDisplay="Top" AllowAutomaticUpdates="true" DataSourceID="ObjectDataSource" DataKeyNames="Id">
<Columns>
<telerik:GridBoundColumn DataField="Id" DataType="System.Int32" FilterControlAltText="Filter Id column" HeaderText="Id" SortExpression="Id" UniqueName="Id" Display="false" ReadOnly="true">
<telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Name column" HeaderText="Name" SortExpression="Name" UniqueName="Name"/>
</Columns>
</MasterTableView>
</telerik:radGrid>
And so in my backend i hook on the event like so:
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e) {
// Get the ID for the specific row which had the "Edit" link pressed.
}
i would prefer if i was able to have the ID stored in a int.
int i = e.Somthing.Something.Darkside;
I have searched far and wide with no success and i hope someone can come to my rescue on this fine Friday.
I am sorry if i make no sense, English is not my primary language and my way of thinking may be off (Looking at something that should be simple for 3 hours does that to you doesn't it?).
Upvotes: 1
Views: 2614
Reputation: 11154
Please try with the below code snippet.
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
GridEditableItem item = e.Item as GridEditableItem;
int Id = Convert.ToInt32(item.GetDataKeyValue("Id").ToString());
//Access edit row ID value here -- using datakey
string Name = (item["Name"].Controls[0] as TextBox).Text;
// Get Name field updated value here
int index = item.ItemIndex;
// Access edit row index here
}
Let me know if I am not understand your requirement.
Upvotes: 1
Reputation: 2246
In the event handler for RadGrid1_UpdateCommand
, get the current item and then from there you can calculate the item's row index:
GridEditableItem editItem = e.Item as GridEditableItem;
int myIndex = (editItem.RowIndex / 2) - 1;
The RowIndex
value is a multiple of 2, and is sort of 1's based (starts at 1, not zero). So with this calculation, you get the following (what I consider what you would expect):
RowIndex myIndex 2 0 4 1 6 2 ...
Upvotes: 0