Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.

The code below creates a GridView control that have a hyperlink column which

sends the ID to other page:

Here is the simple code which you can use: 

 <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="White"
            BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" 

GridLines="None" AutoGenerateColumns="False">
            <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
            <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
            <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
            <Columns>
                <asp:BoundField DataField="CategoryID" />
                <asp:HyperLinkField DataNavigateUrlFields="CategoryID"

 DataNavigateUrlFormatString="SmallWindow.aspx?id={0}"
                    DataTextField="CategoryName" NavigateUrl="SmallWindow.aspx" />
                <asp:BoundField DataField="Description" />
            </Columns>
        </asp:GridView>

So, now when you click the CategoryName you will be redirected to SmallWindow.aspx page.

 

powered by IMHO

 

Posted on Sunday, October 30, 2005 12:42 PM | Back to top


Comments on this post: Hyperlink Columns in GridView Control

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
Azam

Thanks for a very interesting article on hyperlinking a column with the gridview (I am new to asp.net 2.0). Can I ask how do you change the anchor text to just display a word such as Comments rather than using the datatextfield to show the id?

Thanks

Bob
Left by Bob Cummings on Dec 21, 2005 6:11 AM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
I want to have a bound column as a hyperlink,
on clicking on which it will populate another datagrid having the presene field as the primary key of another table.I am using views.
Thanks in advance
Left by kiran on Mar 27, 2006 8:04 PM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
How can I open a pop window for the Databound column....and even ge the ID value on the pop page???
Left by Tina on Oct 02, 2006 10:13 AM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
Is there a way to get the new window to pop-up?
Left by David on Nov 01, 2006 10:38 AM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
Use the Target attribute of the HyperLinkField.
Left by AzamSharp on Nov 01, 2006 11:56 AM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
I got a problem showing the hyperlink, i see the hyperlink in my program, but when showing it in the browser only the text is shown, the hyperlink "functionality" is gone.
It worked, and suddenly it idnd't work anymore. Anybody know a solution?!?!
Left by daniel on Nov 15, 2006 3:15 AM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
I found the problem, i got a DATE field in the datanavigateurlformatstring hich causes the explorer to place the link as normal text.

the solution is to put in the following:
~/somepage.aspx?ID={0:d}

this way the field is known as date and is handled correctly.
Left by daniel on Nov 15, 2006 8:23 AM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
Thanks a lot.This article help me to solve my problem.
Left by KOSOL on Jan 18, 2007 12:00 AM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
Is there a way when you click on the hyperlink, passing the ID of the Category ina queryString, to open a window that shows that CategoryName. Using Northwind as an example, the new page would show the category name as well as the associated products.
The resulting page would look like this, for that particular category whose Id was passed in the next page:
Category Products
Beverages Beer
Wine
Soy Milk
Fruit Juice

Thanks for the help.

Gail
Left by Gail on Mar 15, 2007 1:33 PM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
Thanks Lot MR......
Left by Harishankar on Jun 11, 2007 4:14 PM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
Thanks a lot. Worked like a charm!
Left by Tierra on Aug 01, 2007 10:22 AM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
hii
I m using hyperling & Checkbox in my grid when i click on hyperling (Which is a primary key) it simple redirect to next desired page and i get value of PK by qery string.bt when i try to access value on the same page where i apply grid i got enable to do so.IS IT ANY WAY TO ACCESS ELEMENT VALUE OF HYPERLING ON SAME PAGE I TRY this bt it nt work
string PK = gridview.row[x].cell[hyperlinkcell].Terxt;

Bt it is nt woking :(
Left by Akki on Aug 22, 2007 12:16 AM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...

I want to have a bound column as a hyperlink,
on clicking on which it will populate another datagrid having the presene field as the primary key of another table.I am using views.
Left by Reena Dahiya on Nov 01, 2007 10:03 PM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
Cheers helped me loads!

Keir
Left by Keir on Nov 07, 2007 12:41 AM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...

nice code, help me lot !!!!!

Thanks,
Rajendra
Left by Rajendra Dhanora on Dec 03, 2007 1:48 AM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
Cool dude...It worked very nicely...n helped me a lot!!! thanks buddy :)
Left by Vivek on Dec 06, 2007 1:50 AM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
Good Link. Thanks.
Left by dotnetuncle .NET Interviews on Jan 20, 2008 11:49 PM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
Thanks a lot, answerd my question exactly!!!!
Left by Tim Dunne on Feb 04, 2008 11:50 PM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
Thanks, code worked great though I only required:

<asp:HyperLinkField Text="text to show user" datanavigateurlfields="id" datanavigateurlformatstring="mypage.aspx?id={0}" />

To do the job :D

Thanks
Left by Andrew on Mar 08, 2008 11:18 PM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
Does this code allows us to transfer a id to another page which is the one of the attribute in the gridview????

I am not sure about that. If anoyone could help me with my asp.net pls e-mail me at winxclub_flora_sky@hotmail.com

Thanks alot...
Left by Vani on Apr 22, 2008 7:16 PM

# re: Hyperlink Columns in GridView Control
Requesting Gravatar...
More Help pls
Left by Priya on Apr 22, 2008 7:19 PM

# Hyperlink Columns in GridView Control
Requesting Gravatar...
How to open another from by clicking one column of a row of gridview by passing one column value "serial number" (i'e first column )
Left by pankaj kumar on Dec 28, 2010 4:52 PM

Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net