Home All Groups Group Topic Archive Search About

Can assign multiple keys to datkeys of datagrid

Author
6 Jun 2005 9:55 PM
TS
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

Author
6 Jun 2005 10:16 PM
Brock Allen
In v1.1 you're stuck with a single column. In 2.0 they allow multiple columns.

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



Show quoteHide quote
> 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
>
Author
7 Jun 2005 6:00 AM
Steven Cheng[MSFT]
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.)
Author
7 Jun 2005 3:57 PM
TS
so you would add an attribute for each primary key? (instead of a single key
with multiple values)?


Show quoteHide quote
"Steven Cheng[MSFT]" <v-sch***@online.microsoft.com> wrote in message
news:7LfU4YyaFHA.2476@TK2MSFTNGXA01.phx.gbl...
> 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.)
>
>
Author
8 Jun 2005 10:03 AM
Steven Cheng[MSFT]
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.)
Author
7 Jun 2005 5:48 AM
Teemu Keiski
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




Show quoteHide quote
"TS" <manofsteele1@nospam.nospam> wrote in message
news:efRWCKuaFHA.1660@tk2msftngp13.phx.gbl...
> 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
>
>