ASP.NET GridView shows error in designer when setting datakeynames

Posts   
 
    
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 25-Sep-2006 16:27:27   

I am not sure if this thread is related (http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7616&HighLight=1) but here is the issue.

When you bind an asp.net grid view to an LLBLGenProDataSource2 control, and set the DataKeyNames property to a value the GridView displays an error in the designer which reads "DataBinding: 'System.Data.DataRowView' dies not contain a property with the name 'CustomerId'"

Steps to reproduce: Drag and drop a LLBLGenProDataSource2 control onto the designer.
Configure the data source.
Select TypedView for ContainerType Select the TypedView to use Drag and drop a grid view onto the designer Choose a data source, select the newly added data source control Set the DataMember property of the GridView to DefaultView Click the elipses in the DataKeyNames property of the Property Browser Add 1 or more fields from the "Data Fields Collection Editor" to the DataKeyNames property

My file version of the ORMSupportClasses.NET20 is v2.0.0.60911 and the modified date is Monday, September 11, 2006, 5:30:56 PM

The code runs as expected, but the gridview displayed in the designer hosed.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 25-Sep-2006 16:34:45   

Be sure the casing is correct (of the fieldname in the grid's datakeynames). Is the casing correct?

Frans Bouma | Lead developer LLBLGen Pro
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 25-Sep-2006 19:43:32   

I did not manually enter the name. I picked it from the list of available fiels that is displayed in the dialog that opens when I click the elipses.

But the casing of the name is correct all the way from the html of the designer through the generated code:

GridView Definition


<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="CustomerInfoDataSource" PageSize="20" AutoGenerateSelectButton="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" CellPadding="0" DataKeyNames="CustomerId" DataMember="DefaultView">
    <Columns>
        <asp:BoundField DataField="CustomerId" HeaderText="CustomerId" SortExpression="CustomerId" Visible="False" />
        <asp:BoundField DataField="CountryRegionName" HeaderText="CountryRegionName" SortExpression="CountryRegionName" />
        <asp:BoundField DataField="StateProvinceName" HeaderText="StateProvinceName" SortExpression="StateProvinceName" />
        <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
        <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
        <asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress" SortExpression="EmailAddress" />
        <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
    </Columns>
</asp:GridView>


Data Column Initialization in Generated TypedView


            _columnCustomerId = new DataColumn("CustomerId", typeof(System.Int32), null, MappingType.Element);
            _columnCustomerId.ReadOnly = true;
            _columnCustomerId.Caption = @"CustomerId";
            this.Columns.Add(_columnCustomerId);

CustomerId property defined in Generated Row Class


        public System.Int32 CustomerId 
        {
            get 
            {
                if(IsCustomerIdNull())
                {
                    // return default value for this type.
                    return (System.Int32)TypeDefaultValue.GetDefaultValue(typeof(System.Int32));
                }
                else
                {
                    return (System.Int32)this[_parent.CustomerIdColumn];
                }
            }
            set 
            {
                this[_parent.CustomerIdColumn] = value;
            }
        }

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 25-Sep-2006 21:51:39   

Hi,

It should not look for the customerID property in "System.Data.DataRowView" but rather in "yourTypedView_Row".

That's because you set the DataMember property of the GridView to DefaultView, Try to set it to the typedview instead.

Hope that helps

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 26-Sep-2006 15:43:41   

I followed the same steps listed when reporting the bug except this time I put "IndividualCustomerRow" into the DataMember property before setting the DataKeyNames property. After setting the DataKeyNames property to CustomerId, the error still occurs in the designer.

You solution does not resolve the error in my situation and my development environment.

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 26-Sep-2006 16:02:55   

Downloaded and installed 9-23-2006 release and the issue still exists.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 26-Sep-2006 16:18:56   

I think I understand why this is: a typedview doesn't define a primary key field set in the datatable. So no field reported by the datasourcecontrol is a PK field.

Frans Bouma | Lead developer LLBLGen Pro