Search

Monday, February 3, 2014
0 comments

Add Hyperlink field into GridView control in ASP.NET

8:39 AMMonday, February 3, 2014
Step-1 : First bind your GridView using SqlDataSource control
Step-2 : Select 'Edit Column' link using show smart tag.


Edit Columns of gridview in asp.net

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="int" DataSourceID="SqlDataSource1" GridLines="None" Width="43px">
        <Columns>
            <asp:HyperLinkField DataNavigateUrlFields="address" DataTextField="name" 
                Text="Fav. Links" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>" 
        SelectCommand="SELECT * FROM [Table1]"></asp:SqlDataSource>
    </form>
</body>
</html>
Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top