A hyperlinked Column in GridView with captured ID

C

coosa

In an asp.net 2.0 GridView web control, is it possible to display one
column as a hyperlink which displays a name, such as item_name from a
db table, but capures the item_id when clicked?
If yes, then how?
 
J

Jeff Dillon

Go to the Columns property in design view with the grid and bring up the
Collection dialog. Click the Help button to learn about the various settings
for the Hyperlink column. It has just what you are looking for

Jeff
 
C

coosa

I did actually; as a sample:
<asp:HyperLinkField DataNavigateUrlFields="COMPANY_ID"
DataNavigateUrlFormatString="~/Company/Page.aspx?COMPANY_ID={0}"
DataTextField="COMPANY_ID" DataTextFormatString="Info"
HeaderText="Company Info" Text="Details" />
is nested inside <columns> in the Gridview.
The only displayed item for this column are always hyperlinked "Info"
in the DataTextFormatString property.
So what i want semantically is to display the actual company name as a
hyperlink. I have tried to replace for instance
DataNavigateUrlFields="COMPANY_NAME" with
DataNavigateUrlFields="COMPANY_ID", but it had no effect. When i remove
DataTextFormatString="Info", then the company_id is displayed instead
as a hyperlink.
 
J

Jeff Dillon

Not sure why you are showing the source code. I simply use the Collection
dialog, and it works. You are not reading the help closely enough. I JUST
went though this myself at work here this morning. They mention how one
setting over rides the others. You want DataTextField (what displays) as
Company Name, and DataURLField (used in the URL) as Company ID

Jeff
 
C

coosa

And where is that help exactly located?
I followed the dialog in the design view -> Collection but there is no
help.
Can you at least specify WHICH property is responsible to display the
CompanyName and which property is responsible to capture the CompanyId?

Best regards
 
J

Jeff Dillon

I just did!

In the dialog, Company Name would be Text Field, and Company ID would be URL
Field.

I'm using VS 2003

There is a Help button next to the Ok and Cancel buttons in the
Columns/Collection property dialog box

Jeff
 
C

coosa

Thanks alot. It worked now and it was that simple!!
But just for the record, there is no helo beside the OK button in VS
2005 dialog box of the collection
 

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,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top