Weird Error: Cannot find DataKey Column or Relation

3 posts, 0 answers
  1. Brian Mains
    Brian Mains avatar
    485 posts
    Member since:
    Oct 2008

    Posted 29 Nov 2010 Link to this post

    Hello,

    When l have a RadGrid with the following defined:

    <ClientSettings>
    <ClientEvents OnCommand="rg_Command" />
    </ClientSettings>

    I get an error that it cannot find a DataKeyColumn or DataRelation for a DataKeyName I have defined in the grid... on inspection of the grid, when this is defined and no data is present, it binds an empty DataTable with 11 rows, but it's missing the DataKeyName?  What is this table and why is this happening?

    Thanks.
  2. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 30 Nov 2010 Link to this post

    Hi Brian,

    The OnCommand event is used for an operation in the grid via web service or to detect what type of command is raised on the client. When you attach handler to the ClientSettings.ClientEvents.OnCommand event and the RadGrid is not bound to any data it is prepared for client side databinding. However in client side databinding you could not use the DataKeyNames, so the exception is thrown.
    To achieve the desired functionality and avoid the error you could try binding the RadGrid initially to the empty array of objects:
    void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        RadGrid1.DataSource = new object[] { };
    }

    Please give it try and let me know if it helps you.

    Greetings,
    Radoslav
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Brian Mains
    Brian Mains avatar
    485 posts
    Member since:
    Oct 2008

    Posted 30 Nov 2010 Link to this post

    Hello,

    That did help; the issue for me was I was binding in PreRender event, so I guess that was happening later than the grid preferred, because I was binding an empty array, and I still got the error.  But it happened later.  Also, even better for my scenario, setting the ClientDataKeyNames to the same value worked.

    Thanks.
Back to Top