|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Can assign multiple keys to datkeys of datagridIs 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 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 > 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.) 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.) > > 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.) 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. -- Show quoteHide quoteTeemu Keiski MCP, Microsoft MVP (ASP.NET), AspInsider ASP.NET Forum Moderator, AspAlliance Columnist http://blogs.aspadvice.com/joteke "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 > >
03 dropdownlist selectedindexchanged not firing in usercontrol on
Why no richtextbox in Web Controls? Mystery ASP.NET Error htmlinputfile - accept Gridview, using Callbacks when Sorting and Paging textbox postback Div and code behind on click event dataformatstring for dates in datagrid Dyamically add user control, along with properties? can you convert an in-memory bitmap render in a web control image ? |
|||||||||||||||||||||||