This is a migrated thread and some comments may be shown as answers.

Weird Error: Cannot find DataKey Column or Relation

2 Answers 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian Mains
Top achievements
Rank 1
Brian Mains asked on 29 Nov 2010, 07:33 PM
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 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 30 Nov 2010, 02:43 PM
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.
0
Brian Mains
Top achievements
Rank 1
answered on 30 Nov 2010, 04:57 PM
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.
Tags
Grid
Asked by
Brian Mains
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Brian Mains
Top achievements
Rank 1
Share this question
or