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

Getting Datakeys of selected edit row

3 Answers 335 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marcus
Top achievements
Rank 1
Marcus asked on 08 Nov 2008, 02:16 PM
HI,

I have a datagrid that is using a custom user control for insert/edit. When the user clicks 'edit' on a row I want to pass the Id datakey into my user control so that I can use it to do a db lookup. I'm sure it can be done but can't figure out how. Can anyone provide me with a solution?

Thanks!

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Nov 2008, 06:47 AM
Hello Marcus,

Check out the following code to access the datakeyvalue.
aspx:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound" > 
 <MasterTableView DataKeyNames="Category" DataSourceID="SqlDataSource1" > 
   .... 

cs: 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem eeditedItem = e.Item as GridEditableItem; 
            UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); 
            //access the datakeyvalue 
            string strtxteditedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Category"].ToString(); 
           
        } 
    } 
 

Thanks
Princy.
0
Marcus
Top achievements
Rank 1
answered on 10 Nov 2008, 09:21 AM
Thanks Princy, that works great!

Is there an automated way to pass the datakey to the user control? I'm currently passing it as a session variable but I wonder if there's another (better) option?

Thanks,

Marcus.
0
Princy
Top achievements
Rank 2
answered on 11 Nov 2008, 07:40 AM
Hi,

A  suggestion would be to create a property for the user control and set the property of the control to the required value in the ItemDataBound event.


Thanks,
Princy
Tags
Grid
Asked by
Marcus
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Marcus
Top achievements
Rank 1
Share this question
or