Can't specify DataKeyName for GridView

Posts   
 
    
rmachin
User
Posts: 2
Joined: 03-Jan-2007
# Posted on: 03-Jan-2007 12:07:37   

I am using a LLBGenProDataSource in VS2005 SP1. The dataContainerType is a TypedView.

I am using LLBLGenPro Version 2.0.0.0 Final (July 12th 2006).

I have a gridView using the datasource, but whenever I try and Specify a DatakeyName, the GridView is no longer rendered in the designer and the following error is displayed:

GridView - PoHeaderInfo

There was an error rendering the control. DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'PoheadId'

Am I doing something wrong or is this a bug?

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 03-Jan-2007 13:24:55   
rmachin
User
Posts: 2
Joined: 03-Jan-2007
# Posted on: 03-Jan-2007 14:02:51   

Thanks. I had seen that thread, but can't see why a datakey cannot be defined. In the past I have defined datakeys for gridviews based on the MS object data source and these have worked fine. I can understand that if no primary key is available in the database view then one cannot be determined by the TypedView, however should it not be possible to specify one?

I am using the typedView and a gridview to display purchase order header information. I then intended for the user to be able to click on a give PO header to drill down into the line items. Is there another way of acheiving this without obtaining a datakey following the RowCommand event? Should I not be using TypedViews?

My proposed code would have been:

protected void POHeaderInfo_RowCommand(object sender, GridViewCommandEventArgs e) { //check that the link has been clicked in the Action / View column if (e.CommandName == "View") { //need to get the index int idx = Convert.ToInt32(e.CommandArgument); //now we can get the datakeys DataKey dkey = POHeaderInfo.DataKeys[idx]; string PoID= dkey["PoheadId"].ToString(); } }

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 03-Jan-2007 14:24:20   

You may use a hidden column to hold the PoheadId.