Control : DevExpress - ASPxGridView - 9.2.6
Problem Statement
We 'll be assigning the datasource to the ASPxGridview and set KeyFieldName and call the DataBind method to get the data displayed in the ASPxGridview. Below is the partial code of BindData() method,
ASPxGridview.Datasource = DataTable;
ASPxGridview.KeyFieldName = "PrimaryKey";
ASPxGridview.DataBind();
This method is being called from OnLoad and button click event.
This is working fine with 9.1.3. But when we try to convert it to 9.2.6 it shows the below error
The KeyFieldName is not exists in the underlying datasource...
Solution
You can assign the datasource there itself. But need to move the keyfieldname assignment and DataBind() call to OnPreRender method as given below..
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
ASPxGridview.KeyFieldName = "KeyID";
ASPxGridview.DataBind();
}
OnLoad method for your reference..
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if(Page.IsPostBack)
{
EnsureChildControls();
BindData();
}
}