Can assign multiple keys to datkeys of datagrid

T

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
 
B

Brock Allen

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

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.
 
S

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.)
 
T

TS

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

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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top