I want to select a row and do something with it's Id column, however it isn't working and I'm running into the error mentioned at the end. Heres what I got -
<dx:ASPxGridView ID="ASPxGridView1" runat="server" Font-Names="Arial" Font-Size="Small"
Width="100%" ClientInstanceName="grid" oncustomcallback="grid_CustomCallback"
onbeforegetcallbackresult="ASPxGridView1_BeforeGetCallbackResult"
EnableCallBacks="False" EnableRowsCache="False" KeyFieldName="ID">
... Columns here ...
<ClientSideEvents ContextMenu="OnContextMenu" SelectionChanged="OnSelectionChanged" />
</dx:ASPxGridView>
protected DataTable GetHeadlineData(SqlDataReader rdr)
{
DataTable headlineTable = new DataTable();
headlineTable.Load(rdr)
headlineTable.PrimaryKey = new DataColumn[] { headlineTable.Columns["ID"] };
return headlineTable;
}
DataTable dt= new DataTable();
dt= FillGrid(); //this function internally calls the above GetHeadlineData function
Session["headTable"] = dt;
ASPxGridView1.DataSource = Session["headTable"];
ASPxGridView1.KeyFieldName = "ID";
ASPxGridView1.DataBind();
function OnSelectionChanged(s, e) {
grid.GetSelectedFieldValues("ID", OnGetSelectedFieldValues);
}
function OnGetSelectedFieldValues(result) {
for (var i = 0; i < result.length; i++)
for (var j = 0; j < result[i].length; j++) {
document.getElementById('selectedRowDiv').innerHTML = result[i];
}
}
A primary key field specified via the KeyFieldName property is not found in the
underlying data source. Make sure the field name is spelled correctly. Pay
attention to the character case.
What eventually worked was using the RowClick event instead of the SelectionChanged.