Can assign multiple keys to datkeys of datagrid

Discussion in 'ASP .Net Web Controls' started by TS, Jun 6, 2005.

  1. TS

    TS Guest

    Is it possible to have more than one field assigned to a datagrid's
    datakeyfield in the case of a clustered primary key for a table?

    thanks
     
    TS, Jun 6, 2005
    #1
    1. Advertising

  2. TS

    Brock Allen Guest

    In v1.1 you're stuck with a single column. In 2.0 they allow multiple columns.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Is it possible to have more than one field assigned to a datagrid's
    > datakeyfield in the case of a clustered primary key for a table?
    >
    > thanks
    >
     
    Brock Allen, Jun 6, 2005
    #2
    1. Advertising

  3. TS

    Teemu Keiski Guest

    Hi,

    if you create a combined column (comma-separated values for example, from
    multiple columns) in the query and assign this field to the DataKeyField,
    you could have somewhat similar feature. You just need to parse the CSV when
    you need to access individual key values.

    As Brock said, solid support for this features comes officially with v2.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsider
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke




    "TS" <> wrote in message
    news:...
    > Is it possible to have more than one field assigned to a datagrid's
    > datakeyfield in the case of a clustered primary key for a table?
    >
    > thanks
    >
    >
     
    Teemu Keiski, Jun 7, 2005
    #3
  4. Hi TS,

    As Brock has mentioned, in the current version of ASP.NET, the DataGrid's
    DataKeyField is limited to single column field. However, if you do need to
    save the multi-primary key info in the DataGrid's DataGridItems, we can use
    some other means to workaround it:

    We can make use of the webserver control's Attributes collection and put
    each DataGridRow's primarykey info in a certain Attribute Item, like:

    private void dgString_ItemDataBound(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)
    {
    e.Item.Attributes.Add("pk_value", "pk values from datasource");
    }
    }


    Then, in the sequential update/delete events, we can retrieve those info
    from the Item's corresponding Attribute.

    Hope helps. Thanks,

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Jun 7, 2005
    #4
  5. TS

    TS Guest

    so you would add an attribute for each primary key? (instead of a single key
    with multiple values)?


    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hi TS,
    >
    > As Brock has mentioned, in the current version of ASP.NET, the DataGrid's
    > DataKeyField is limited to single column field. However, if you do need to
    > save the multi-primary key info in the DataGrid's DataGridItems, we can

    use
    > some other means to workaround it:
    >
    > We can make use of the webserver control's Attributes collection and put
    > each DataGridRow's primarykey info in a certain Attribute Item, like:
    >
    > private void dgString_ItemDataBound(object sender,
    > System.Web.UI.WebControls.DataGridItemEventArgs e)
    > {
    > if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > ListItemType.AlternatingItem)
    > {
    > e.Item.Attributes.Add("pk_value", "pk values from datasource");
    > }
    > }
    >
    >
    > Then, in the sequential update/delete events, we can retrieve those info
    > from the Item's corresponding Attribute.
    >
    > Hope helps. Thanks,
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    >
     
    TS, Jun 7, 2005
    #5
  6. Hi TS,

    Thanks for your response.
    Yes, storing them in multi attributes is ok. Also, we can join those values
    into single string expression (through a certain separator char). In fact,
    if the ASP.NET DataGrid buildin provide such as fucntion, it'll also use
    such means to serialize the values into one string or binary value and
    store in ViewState.

    Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Jun 8, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sandeep Kanwal

    serial keys/validation keys

    sandeep Kanwal, Oct 29, 2004, in forum: C++
    Replies:
    1
    Views:
    593
    Mike Wahler
    Oct 29, 2004
  2. Harry George
    Replies:
    9
    Views:
    719
    sonal
    Jun 13, 2006
  3. Replies:
    10
    Views:
    735
    Daniel T.
    Feb 3, 2006
  4. TS

    assigning multiple keys to datkeys of datagrid

    TS, May 23, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    140
  5. H?seyin Erg?n
    Replies:
    3
    Views:
    192
Loading...

Share This Page