Fix “DataKeyField Is Invalid” Error in Grid Binding
New DiscussionI’m doing some tests on WebDataGrid in ASP.Net 4.0, and I have this error:
[InvalidOperationException: DataKeyField is invalid]
Infragistics.Web.UI.Framework.Data.DataSourceAdapter.Select(DataSourceSelectArguments arguments) +651
Infragistics.Web.UI.Framework.Data.DataSourceObjectView.ExecuteSelect(DataSourceSelectArguments arguments) +73
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
Infragistics.Web.UI.GridControls.WebDataGrid.DataBind() +974
Infragistics.Web.UI.Framework.Data.FlatDataBoundControl.EnsureDataBound() +73
Infragistics.Web.UI.GridControls.WebDataGrid.EnsureDataBound() +186
Infragistics.Web.UI.GridControls.WebDataGrid.CreateChildControls() +75
System.Web.UI.Control.EnsureChildControls() +102
Infragistics.Web.UI.GridControls.WebDataGrid.EnsureChildControls() +129
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
My WebDataGrid in .aspx page is defined in this way:
<ig:WebDataGrid runat=”server” ID=”grdOrders” Height=”400px” Width=”600px” EnableViewState=”true”>
<Behaviors>
<ig:Sorting Enabled=”true”></ig:Sorting>
<ig:Filtering Enabled=”true”></ig:Filtering>
<ig:ColumnMoving Enabled=”true”></ig:ColumnMoving>
<ig:EditingCore Enabled=”true”>
<Behaviors>
<ig:CellEditing Enabled=”true”></ig:CellEditing>
</Behaviors>
</ig:EditingCore>
</Behaviors>
</ig:WebDataGrid>
While in the code behind I have only this code:
Dim dtOrders As DataTable
Dim sSql As String = “SELECT OrderYear,OrderType,OrderNumber,CustomerCode FROM Orders WHERE OrderYear=2012”
LoadTable(DBConnection, dtOrders, “Ordini”, sSql, True, New String() {“OrderYear”, “OrderType”, “OrderNumber”})
grdOrders.DataSource = dtOrders
grdOrders.DataKeyFields = “OrderYear,OrderType,OrderNumber”