Search
Categories
  ASP.NET
Visual C#
Visual Basic
.NET Framework
ADO.NET
AJAX
LINQ
Java
 
Tutorial Rating
 
4.2 out of 5


Total Votes: 21
         
1 2 3 4 5
 




Using Hyperlink columns in GridView

Author: Waqas Anwar - Posted Date: 30-March-2008 - Category: ASP.NET   
Bookmark and Share
GridView control is one of the most powerful controls in ASP.NET 2.0. This control displays database records in typical tabular form, and provides features such as Sorting, Paging, Selection and Editing without writing a single line of code. It also has many different types of fields (columns) such as hyperlinks, images, checkboxes etc.
 
In the following tutorial, I will show you different techniques you can use to display hyperlinks in GridView.  For this tutorial I am using Microsoft famous sample database Northwind and I am joining Products and Suppliers tables to display ProductID, ProductName, UnitPrice, SupplierID and CompanyName in the GridView. 


hyperlink_fields.gif



Databound hyperlink text with dynamic query string URL

<asp:HyperLinkField 
      DataTextField="ProductName" 
      HeaderText="Product Name" 
      SortExpression="ProductName" 
      DataNavigateUrlFields="ProductID" 
      DataNavigateUrlFormatString="ProductDetails.aspx?ProductID={0}" />


Databound hyperlink text with multiple fields in the query string URL

<asp:HyperLinkField 
      DataNavigateUrlFields="SupplierID, CompanyName" 
      DataNavigateUrlFormatString="SupplierDetails.aspx?SupplierID={0}&CompanyName={1}"
      DataTextField="CompanyName" 
      HeaderText="Supplier" 
      SortExpression="CompanyName" />
                   

Static hyperlink text with dynamic query string URL
 
<asp:HyperLinkField 
      DataNavigateUrlFields="ProductID" 
      DataNavigateUrlFormatString="ProductDetails.aspx?ProductID={0}"
      HeaderText="View Details" 
      SortExpression="ProductName" 
      Text="View Details" />


Static hyperlink text with external URL opening in new browser window

<asp:HyperLinkField 
      Text="Amazon" 
      NavigateUrl="http://www.amazon.com/
      HeaderText="Search Online" 
      Target="_blank" />


Databound hyperlink text with custom format to display link text
 
<asp:HyperLinkField 
      DataTextField="UnitPrice" 
      DataTextFormatString="GBP {0}" 
      DataNavigateUrlFields="ProductID" HeaderText="Unit Price"
      DataNavigateUrlFormatString="ProductDetails.aspx?ProductID={0}"   />

 



RELATED TUTORIALS

  Editing Data using ASP.NET GridView Control
  Deleting multiple Rows in GridView using Checkbox
  Display Microsoft Excel File in ASP.NET GridView
  Displaying Total in Footer of GridView
  Using Checkbox in ASP.NET GridView Control
  Formatting GridView output based on Data
  Using Button columns in GridView

LEAVE YOUR COMMENTS LEAVE YOUR COMMENTS
 Name (required)  
 Email (required
 Website


 
POSTED COMMENTS POSTED COMMENTS

Thanks for give this type of tutorial,it is helpful for learning dotnet 2.0.
great articles related to gridview.

Thanks
Santosh Kumar
http://www.operativesystems.com
Posted by santosh kumar on Monday, June 23, 2008

Using Hyperlink columns in GridView Example "Static hyperlink text with dynamic query string URL" passes the value of the QueryString as literal text i.e. ProductID{0} and not the value of the ProductID itself.
Posted by Clinton Gallagher on Wednesday, August 05, 2009

wow ! i never expect this kind of responce from your website i realy very happy to useful this.! wish u all success.
Posted by kulandaivelan on Wednesday, March 17, 2010

 


 
 
 

Categories

My Portfolio

Website Links


Copyright @ 2009 EzzyLearning.com