Using 'DataKeyNames' on an ASP.NET GridView control, causes exception on DataBind() call
- by azam
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.