I have the following setup in my RadGrid lines in bold contain my database table primary key named LinkAnalysisId
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton">
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="LinkAnalysisId" HeaderText="Link ID" ReadOnly="true"
ForceExtractValue="Always" ConvertEmptyStringToNull="true" Display="False" />
<telerik:GridHyperLinkColumn FilterControlAltText ="Filter LinkID2 column"
Uniquename="LinklId2" DataNavigateUrlFormatString ="/SubjectList2.aspx?LinkID={0}"
DataTextField="LinkAnalysisName" HeaderText="Link Analysis Name"
DataNavigateUrlFields="LinkAnalysisId" />
<telerik:GridBoundColumn DataField="LinkAnalysisName" HeaderText="LinkAnalysisName" SortExpression="LinkAnalysisName"
UniqueName="LinkAnalysisName" Display="False">
Other bound columns are not shown when I update a records and try to save I run this C# code
protected void RadGrid1_UpdateCommand(object sender, Web.UI.GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); var linkAnalysisId = (int)RadGrid1.MasterTableView.Items[0].GetDataKeyValue("LinkAnalysisId"); //retrive entity from the Db var record = DbContext.LinkAnalysis.Where(n => n.LinkAnalysisId == linkAnalysisId).FirstOrDefault(); if (record != null) { //update entity's state editableItem.UpdateValues(record); try { //save chanages to Db DbContext.SaveChanges(); } catch (System.Exception) { ShowErrorMessage(); } } }
var linkAnalysisId = (int)RadGrid1.MasterTableView.Items[0].GetDataKeyValue("LinkAnalysisId");which sets the linkAnalysis variable is not getting the correct ID number so it appears I have something wrong. In debug mode when I inspect the values in the var editableItem I am seeing the correct linkAnalysis ID number it is just the code above is not getting the right record what have I done wrong here?
Thanks