Display an hyperlink column in gridview using TemplateField

  • Thread starter Thread starter Valli
  • Start date Start date
V

Valli

Hi,

I need to display an hyperlink column in gridview where if the user
clicks that column the page should move to the selected page.
I have got help from this group & started using template field. After using
this, I couldnt see a column supporting hyperlink.
In the gridviews first column header, there appears an hyperlink with the
first record link displaying. That also only in header overwriting with the
first column caption.

can anyone help me in this..

My code follows here...

<asp:TemplateField>
<ItemTemplate>

<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%#
Eval("FileLink") %>'

Style="z-index: 100; left: 0px; position: absolute; top: 0px" Text='<%#
Eval("FileLink") %>'></asp:HyperLink>

</ItemTemplate>


</asp:TemplateField>

--FileLink is the datafield name which provides the link
 
If you are using a DataSource, you don't need to use Eval

<asp:HyperLinkField HeaderText="Title"
DataNavigateURLFields="GridNavigationURL" DataTextField="Title"
SortExpression="Title">
<HeaderStyle Width="250px" />
</asp:HyperLinkField>

I use it in this way (GridNavigationURL and Title are column from the
Datasource)

HTH
Braulio


/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------
 
Hi,

Thanks for your help.
If I use this, the field is not getting displayed with the values & also i
couldnt see there any hyperlink way (ie no hand cursor on that column)

Can you help me..
 
<asp:XmlDataSource ID="XmlDataSource1" runat="server">
<Data>
<Links>
<Link FileLink="http://www.microsoft.com"/>
<Link FileLink="http://msdn.microsoft.com"/>
<Link FileLink="http://technet.microsoft.com"/>
</Links>
</Data>
</asp:XmlDataSource>

is the source for

<asp:GridView ID="GridView1" runat="server" DataSourceID="XmlDataSource1">
<Columns>
<asp:HyperLinkField
DataNavigateUrlFields="FileLink"
DataTextField="FileLink"/>
</Columns>
</asp:GridView>

and

<asp:GridView ID="GridView2" runat="server" DataSourceID="XmlDataSource1">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
Text='<%# Eval("FileLink") %>'
NavigateUrl='<%# Eval("FileLink") %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

We could help you, and others, better if you post more of your code rather
than just posting a TemplateField. At least then when someone copies and
pastes the code into a new ASPX page it'll produce a result.
 
Back
Top