Skip to content

Infragistics Community Forum / Web / Ultimate UI for ASP.NET Web Forms / Fix “DataKeyField Is Invalid” Error in Grid Binding

Fix “DataKeyField Is Invalid” Error in Grid Binding

New Discussion
Marco
Marco asked on Mar 30, 2012 11:16 AM

I’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”

LoadTable is a function which executes the SQL script, loads data into the DataTable dtOrders and sets the Primary Key with the fields “OrderYear”, “OrderType”, and “OrderNumber”
The problem is that if I comment the “grdOrders.DataKeyFields…” row, everything works well, but I’m not able to modify any cell in the html page (if I try to do that, at first postback an error saying that I must set DataKeyField is triggered). Instead, if I uncomment that line, the page doesn’t show up and the “DataKeyField is invalid” error is triggered.
How can I solve this? Thanks for any help!
Sign In to post a reply

Replies

  • 0
    Marco
    Marco answered on Mar 29, 2012 4:21 PM

    Add-on: I'm using NetAdvantage ASP.NET 2011 Vol. 2 on Visual Studio 2010 and Framework 4.0.

    • 0
      [Infragistics] Nikolay
      [Infragistics] Nikolay answered on Mar 30, 2012 9:57 AM

      Hi elvandar,

      Thank you for posting in the community.

      Please refer to the attached sample, in which I used DataTable with composite primary key and WebDataGrid with enabled row updating. I would also suggest that you check the following threads which you might find helpful – http://blogs.infragistics.com/forums/p/41108/230234.aspx, http://blogs.infragistics.com/forums/p/58655/298258.aspx.

      Please let me know if this helps.

      • 0
        Marco
        Marco answered on Mar 30, 2012 10:57 AM

        Thanks for your feedback.

         

        I solved the problem a minute ago. It was the, despite capital letters in the query (like "OrderYear") columns were loaded with all lower letters.

        After changing

        grdOrders.DataKeyFields = "OrderYear,OrderType,OrderNumber"

        with

        grdOrders.DataKeyFields = "orderyear,ordertype,ordernumber"

        everything started working.

      • 0
        [Infragistics] Nikolay
        [Infragistics] Nikolay answered on Mar 30, 2012 11:16 AM

        Hello elvandar,

        I'm glad you solved this.

        If you have any other questions, do not hesitate to ask.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Marco
Favorites
0
Replies
4
Created On
Mar 30, 2012
Last Post
14 years ago

Suggested Discussions

Tags

No tags

Created by

Created on

Mar 30, 2012 11:16 AM

Last activity on

Feb 23, 2026 8:40 AM