Is it possible to set the DataKey property of a DataGrid manually?

Discussion in 'ASP .Net' started by Alex, Apr 24, 2004.

  1. Alex

    Alex Guest

    I'm wondering how I can add data to the datakey property of the DataGrid.
    It seems to be read only. How can I populate it?
    I'm using data bound columns, however do not autogenerate the entire grid
    table.
     
    Alex, Apr 24, 2004
    #1
    1. Advertising

  2. Alex

    Teemu Keiski Guest

    Hi,

    you can set DataKeyField programmatically, but of course if you mean
    changing the key value for separate rows (taking it from different column
    based on row), then it is not possible. In that case, you'd pick the data
    column you need via DataItem property of every DataGridItem (in
    ItemDataBound for example).

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

    "Alex" <> wrote in message
    news:...
    I'm wondering how I can add data to the datakey property of the DataGrid.
    It seems to be read only. How can I populate it?
    I'm using data bound columns, however do not autogenerate the entire grid
    table.
     
    Teemu Keiski, Apr 25, 2004
    #2
    1. Advertising

  3. Hi

    Try adding all yo columns in code-behind instead of html ... that is add all columns to yo datagrid programatically
     
    =?Utf-8?B?SG1udA==?=, Apr 25, 2004
    #3
    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. J. Ormaetxe

    Datakey in Datagrid

    J. Ormaetxe, Oct 28, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    6,667
    Egbert Nierop \(MVP for IIS\)
    Oct 29, 2003
  2. Marty
    Replies:
    2
    Views:
    5,170
    microsoft.public.dotnet.languages.csharp
    Feb 19, 2004
  3. Karl

    Re: DataGrid and DataKey

    Karl, Aug 26, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    619
    Weston Weems
    Aug 26, 2004
  4. Joel Reinford

    Datagrid selectedindex from datakey value

    Joel Reinford, Oct 5, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    9,813
    S. Justin Gengo
    Oct 5, 2005
  5. Rod
    Replies:
    2
    Views:
    861
Loading...

Share This Page