Saturday, 18 January 2014

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

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 Serverand 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 


Send Gridview Rows value to another with hyperlinks 

No comments:

Post a Comment