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

Problem with DataKey values

1 Answer 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John John
Top achievements
Rank 1
John John asked on 23 Feb 2010, 10:36 AM
Hi,
    I have some problem with DataKey values. I used to bind certain template controls of the grid based on the datakey values of the grid. I only need to bind when the grid is in edit mode. So i used ItemDataBound event and check the IsEditMode mtthod to bind the details  based on the DataKeyvalues. Every thing is working fine it is getting the records based on primarykey Datakey value.

But the problem occures when i try to add new record. When i click the Insert button it goes to ItemDatabound event and check the IsEditMode but throws error when comes to this line of code,

EID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][

"EID"].ToString();

But i need the above code for binding data when in EditMode, but causes an null error when click Insert Button.

So help me to solve this issue,

-Thanks

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 23 Feb 2010, 11:14 AM
Hi,

You need to differentiate between the Insert and Edit mode in the ItemDataBound/ItemCreated as shown below.This way the code will be executed only for the edit mode.

C#
private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
if(e.Item is GridEditableItem && e.Item.IsInEditMode) 
 if(e.Item.OwnerTableView.IsItemInserted) 
 { 
  //item is about to be inserted 
 } 
 else 
 { 
  //item is about to be edited 
 } 


Shinu
Tags
Grid
Asked by
John John
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or