Add Hyperlink field into GridView control in ASP.NET

February 03, 2014 0 Comments

Step-1 : First bind your GridView using SqlDataSource control
Step-2 : Select 'Edit Column' link using show smart tag.

Edit Columns of gridview in

Step-3 : Now, Appear new field window, which is contain two pane (left or right).
Step-4 : Remove All selected field in left pane.
Step-5 : Add new HyperLink field From Left pane.

Add Hyperlink field into gridview

Step-6: After Added Hyperlink field , you can set DataTextField and DataNavigationUrl field property  from right pane.

Note : Assign Table column name to DataTextField and DataNavigationUrlField.

Step-7 : Click ok
Step-8: Run You application

Code Generate the following output

Add Hyperlink field into GridView control in ASP.NET

Generated Code are:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="int" DataSourceID="SqlDataSource1" GridLines="None" Width="43px">
            <asp:HyperLinkField DataNavigateUrlFields="address" DataTextField="name" 
                Text="Fav. Links" />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>" 
        SelectCommand="SELECT * FROM [Table1]"></asp:SqlDataSource>

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google