DataKeyNames property of DynamicGridView is bugging when it contains multiple columns

Rate It (1)

Last post 02-11-2008 9:09 PM by hyperbolix. 1 replies.

Sort Posts:

  • DataKeyNames property of DynamicGridView is bugging when it contains multiple columns

    02-08-2008, 4:02 PM
    • Loading...
    • hyperbolix
    • Joined on 02-08-2008, 12:05 PM
    • Posts 3

    Focused on very exciting Dynamic Data thare are already pretty stable with latest mid december CTP, I detected one behaviour that could be a bug.

    This code

    <asp:LinqDataSource ID="ds1" runat="server" ContextTypeName="Northwind.NorthwindDataContext" TableName="Products"/>
    <asp:DynamicGridView runat="server" ID="dgv" DataKeyNames="ProductID,CategoryID,SupplierID" DataSourceID="ds1" />
    DataKeyNames property of DynamicGridView has a length of: <%= dgv.DataKeyNames.Length %>

    Displays 1 as a result, when same code using a classic GridView perfectly behaves and returns an expected 3.

    Can anybody confirm this same bug appears outside of me ? 

    Has anybody any idea to fix it myself by derivating my own DynamicGridView while waiting the next ASP.NET 3.6 release.

    Thanks to Microsoft team for such breakthrough in data web application agility.

  • Re: DataKeyNames property of DynamicGridView is bugging when it contains multiple columns

    02-11-2008, 9:09 PM
    Answer
    • Loading...
    • hyperbolix
    • Joined on 02-08-2008, 12:05 PM
    • Posts 3

    I finally find an acceptable work around myself and propose to share it here.

    I discover that the DynamicGridView DataKeyNames property is forced during the OnInit event to contain the list of primary keys of the table associated with the LinqDataSource.

    So by derivating DynamicGridView and providing an overriden event for the OnInit, this solves my issue:

    protected override void OnInit(EventArgs e)
    {
      string[] oldDataKeyNames = this.DataKeyNames; // Save DataKeyNames as declared
      base.OnInit(e);
      if (oldDataKeyNames.Length > 0)
        this.DataKeyNames = oldDataKeyNames; // Restore original declaration
    }

    Hoping that final Microsoft version will take care of it.

Page 1 of 1 (2 items)
Microsoft Communities
Page view counter