Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Convert a Gridview Column into Hyperlink Fields | Gridview Databound Column to a Hyperlink Column

Jan 24, 2013
Introduction

Here I will explain how to convert gridview columns to hyperlink fields in asp.net or convert gridview databound columns to hyperlink Column in asp.net using C#.NET, VB.NET.

Description:
  
In previous articles I explained
Display Gridview Columns as Rows, Set Gridview column width dynamically, jQuery Menu with Bounce Effect,  Get Control values inside of gridview in asp.net, Different type of constraints in SQL Server and many articles relating to gridview, asp.net, jQuery, CSS. Now I will explain how convert gridview columns to hyperlink fields in asp.net using c#, vb.net

To convert gridview columns to hyperlink fields we can write it in different manners based on the requirements check some of samples to convert columns to hyperlink fields

Sample1:

<asp:GridView runat="server" ID="gvrecords"  AutoGenerateColumns="false"
HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="White" DataKeyNames="UserId">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" Text='<%# Bind("Name") %>' NavigateUrl='<%# Bind("Name", "~/Images/{0}") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserName" HeaderText="UserName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="Email" HeaderText="Email" />
</Columns>
</asp:GridView>
Sample2:

<asp:GridView runat="server" ID="gvrecords"  AutoGenerateColumns="false"
HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="White" DataKeyNames="UserId">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href ='<%#"UpdateGridviewvalues.aspx?UserId="+DataBinder.Eval(Container.DataItem,"UserId") %>'> <%#Eval("UserName") %>  </a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserName" HeaderText="UserName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="Email" HeaderText="Email" />
</Columns>
</asp:GridView>
If you want see this in complete example check below article 


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

6 comments :

sumesh said...

yftfdfcgvgtttfgvbvgyg

ranvijay said...

what a feeling ! nice work sir..

Anonymous said...

Thanks this got me started, but I found I had to change the above slightly:


<%#Eval("ID_FieldName") %>

surbhi said...

Thanks dude, Sample 2 helped me. It converted my gridview column value to hyperlink.
Cheers!!!

Unknown said...

Nice work dude....Keep it up...

itsmacyann said...

i got an error =(

Conversion from string "UpdateGridviewvalues.aspx?UserId=" to type 'Double' is not valid.

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.