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

Sometimes we need to get some id from the database table and use that id to generate the link. Something like this:

SomePage.aspx?id=34

You can easily do this by using the following code:

<ItemTemplate>
<asp:HyperLink ID="myHyperlink"
 Text=
'<%# Eval("CategoryName") %>'
 
NavigateUrl='<%# FormatUrl( (int) Eval("CategoryID")) %>'
 
runat="server">[myHyperlink]</asp:HyperLink>
       </ItemTemplate>

And here 
is the FormatUrl method:

 
protected string FormatUrl(int categoryID)
    {
        
return "SomePage.aspx?" + categoryID;
    }

This will create links inside the DataList control. You can try similar approach using Datagrid or GridView controls.

 

powered by IMHO 1.2

Posted on Thursday, December 22, 2005 5:52 PM | Back to top


Comments on this post: Hyperlinks inside the DataList, Datagrid or GridView control

# re: Hyperlinks inside the DataList, Datagrid or GridView control
Requesting Gravatar...
I prefer this syntax (based on a GridView row):

<asp:HyperLinkField HeaderText="CategoryName" Text="<%# Eval("CategoryName") %>" DataNavigateUrlFields="CategoryID" DataNavigateUrlFormatString="~/SomePage.aspx?id={0}" />
Left by Brian on Dec 27, 2005 12:16 PM

# re: Hyperlinks inside the DataList, Datagrid or GridView control
Requesting Gravatar...
Offcourse, you are using the HyperLinkField column. You can view more techniques on www.gridviewguy.com
Left by AzamSharp on Dec 27, 2005 1:05 PM

# re: Hyperlinks inside the DataList, Datagrid or GridView control
Requesting Gravatar...
In a GridView, do you use ASP:HyperlinkField instead of the ASP:BoundField tag? I can't seem to get this to work...trying to put an email link on someone's name.
Left by Lendawg1 on Jan 16, 2006 2:57 PM

# re: Hyperlinks inside the DataList, Datagrid or GridView control
Requesting Gravatar...
Try this:

<A href='mailto:<%# DataBinder.Eval(Container.DataItem,"Author.Email") %>'>
<%# DataBinder.Eval(Container.DataItem,"Author.Name") %>
</A>
Left by AzamSharp on Jan 16, 2006 3:01 PM

# re: Hyperlinks inside the DataList, Datagrid or GridView control
Requesting Gravatar...
The a href tag cannot go under the columns tag...gets underlined in blue (error). Should it be put under a template field tag?
Left by Lendawg1 on Jan 16, 2006 5:18 PM

# re: Hyperlinks inside the DataList, Datagrid or GridView control
Requesting Gravatar...
Yes, put it in the template field.
Left by AzamSharp on Jan 16, 2006 7:51 PM

# re: Hyperlinks inside the DataList, Datagrid or GridView control
Requesting Gravatar...
Right. I put it inside templatefield/itemtemplate tags. It works, but it is kinda fidgity...should have been wizardized.
Thanks for your help
Left by Lendawg1 on Jan 17, 2006 3:13 AM

# re: Hyperlinks inside the DataList, Datagrid or GridView control
Requesting Gravatar...
I want to show Link in GridView with a condition if Condition fail it does not show link and others would show link
Left by Anil on Aug 07, 2006 3:59 AM

# re: Hyperlinks inside the DataList, Datagrid or GridView control
Requesting Gravatar...
good one
Left by abhishek on Feb 13, 2008 3:37 PM

# re: Hyperlinks inside the DataList, Datagrid or GridView control
Requesting Gravatar...
Hello, im using visual web developer for making my proyect for the degree. Im having a problem with dispaying data in a datalist control. When a click the edit template, I drag over a label and a hyperlink, then i databind the hiperlink so it gos to another page sending a value according to what is clicked. The problem is that this hyperlinks only appears once in the datalist and they appear one over the other, i have tried everithing but want work, if somebody knows how to solve this or knows another solution let me know, many thanks
Left by Problem in proyect on May 26, 2008 7:52 PM

# re: Hyperlinks inside the DataList, Datagrid or GridView control
Requesting Gravatar...
can't read black on grey. nice.
Left by viewer on Jun 12, 2008 3:18 AM

Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net