Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 6th, 2003, 09:52 AM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to add 2 cols in DataGrid1.DataKeyField

Hi all,

In my Web form I have DataGrid1 and want to
add 2 cols in DataGrid1.DataKeyField property.
If I had 1 col. it would be DataGrid1.DataKeyField = "ColName1",
but how can I add another more "ColName2"?

Nenad
 
Old May 3rd, 2005, 05:15 AM
Authorized User
 
Join Date: May 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shaileshk Send a message via Yahoo to shaileshk
Default

hi
i have same problem pls help me

shailesh

shailesh kavathiya
 
Old May 3rd, 2005, 06:02 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In few occassions as I found no direct ways, I joined both the fields with a seperator(":") as new key field in my query. used the "strNewKey.split(":")" to sepeate when reading from the datakey collection.


 
Old May 3rd, 2005, 06:41 AM
Authorized User
 
Join Date: May 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shaileshk Send a message via Yahoo to shaileshk
Default

Hi
I can get you
Please explain more


in datagrid propety

url filed = {SubCatID}:{MainCatID} this way not workign

url format string =../category.aspx?id={0}&c={1}

shailesh




shailesh kavathiya
 
Old May 3rd, 2005, 07:09 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I think what Prashant means is that you would have to join the data from the database query into a single column.

SELECT ColName1+':'+ColName2 AS MyKeyField, [more fields] FROM...

Then use that single concatenated field as your primary key because it will be unique:

DataGrid1.DataKeyField = "MyKeyField"

-Peter
 
Old May 3rd, 2005, 07:15 AM
Authorized User
 
Join Date: May 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shaileshk Send a message via Yahoo to shaileshk
Default

Hi Petar
Thanks for replay

but i want to use more then one value so i got main category id as wall as sub category id

i try to make same site like
http://www.iservedesign.com/contact.asp

see leftmenu in this link
how can i pass 2 value in datagrid

shailesh


shailesh kavathiya
 
Old May 3rd, 2005, 07:41 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'm not sure how to explain this any more clearly...

The DataGrid.DataKeyField property does not (to my knowledge) take anything more than a single field. If you have a table/query that uses multiple fields as a primary key then you need to work around this. One option that I explained is to concatenate your primary key fields together and thus form a *unique* single field that you can then use as the DataKeyField. If you join the values together with some known character, you can break them apart to get at the multiple parts of the unique key. What you do with those values is then up to you.

-Peter
 
Old May 3rd, 2005, 07:45 AM
Authorized User
 
Join Date: May 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shaileshk Send a message via Yahoo to shaileshk
Default

Hi peter

Thank for try to explain
i also try other wise i use singe table filed use for link

shailesh


shailesh kavathiya
 
Old May 4th, 2005, 02:09 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

Shailesh,

another way is to create a template column containing a hyperlink and use databinding expression to make a concatenated string containing the values.



Regards
Ganesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
DataKey / DataKeyField / DataKeyNames rsearing ASP.NET 2.0 Basics 0 June 30th, 2008 08:25 PM
dataGrid1.DataBindings.Add() in PDA mahen_pali C# 2005 1 June 3rd, 2008 05:36 AM
How to add 2 columns in DataGrid.DataKeyField drasko ASP.NET 1.0 and 1.1 Professional 4 September 17th, 2004 09:05 AM
DataGrids and DataKeyField booksnore2 Classic ASP Basics 2 July 5th, 2004 08:38 AM
How to add 2 columns in DataGrid1.DataKeyField drasko C# 0 December 6th, 2003 09:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.