Using 'DataKeyNames' on an ASP.NET GridView control, causes exception on DataBind() call

Posted by azam on Stack Overflow See other posts from Stack Overflow or by azam
Published on 2010-05-28T04:50:05Z Indexed on 2010/05/28 4:51 UTC
Read the original article Hit count: 232

Filed under:
|
|
|

Hi I have an ASP.NET 3.5 WebForms application.

Using a GridView control and the DataKeyNames attribute

<asp:GridView ID="data" runat="server" DataKeyNames="ID">
    <Columns>
        <asp:BoundField DataField="ID" /> <!-- this binds -->

If I take out the DataKeyNames="ID" it binds the data. I would really like to try and use DataKeyNames so I don't need to have the ID column in the columns list.

Error:

DataBinding: 'Nmspace.MyClass' does not contain a property with the name '"ID"'.

Please help.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about databinding