Example T517626
Visible to All Users

Grid View for ASP.NET Web Forms - How to create a HyperLink column whose URL depends on several column values

This example demonstrates how to create a GridViewDataHyperLinkColumn whose URL depends on several column values.

Grid columns that contain hyperlinks.

Specify the GridViewDataColumn.UnboundExpression property to create a column's URL:

ASPx
<dx:GridViewDataHyperLinkColumn FieldName="HyperLinkColumn" UnboundType="String" UnboundExpression="'Default2.aspx?id='+[CategoryID]+'&name='+[CategoryName]" VisibleIndex="4"> <PropertiesHyperLinkEdit TextField="CategoryName" DisplayFormatString="Open <b>{0}<b/>"> </PropertiesHyperLinkEdit> </dx:GridViewDataHyperLinkColumn>

You can define the HyperLinkProperties.NavigateUrlFormatString property to add additional text to the complete URL:

ASPx
<dx:GridViewDataHyperLinkColumn FieldName="HyperLinkColumn2" UnboundType="String" UnboundExpression="'?id='+[CategoryID]+'&name='+[CategoryName]" VisibleIndex="4"> <PropertiesHyperLinkEdit TextField="CategoryName" DisplayFormatString="Open <b>{0}<b/>" NavigateUrlFormatString="Default2.aspx{0}"> </PropertiesHyperLinkEdit> </dx:GridViewDataHyperLinkColumn>

You can also configure a custom DataItemTemplate to display links in cells. For more information, refer to the following page: How to use a hyperlink whose argument depends on several cell values in the ASPxGridView.

Files to Look At

Documentation

More Examples

Example Code

Solution/Default.aspx
ASPx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Solution.Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>How to create a column with URLs that depend on several column values.</title> </head> <body> <form id="form1" runat="server"> <dx:ASPxGridView ID="gridView" runat="server" AutoGenerateColumns="False" DataSourceID="ads" KeyFieldName="CategoryID" ClientInstanceName="gridView"> <Columns> <dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="1"> <EditFormSettings Visible="False" /> </dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="2"> </dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="3"> </dx:GridViewDataTextColumn> <dx:GridViewDataHyperLinkColumn FieldName="HyperLinkColumn" UnboundType="String" UnboundExpression="'Default2.aspx?id='+[CategoryID]+'&name='+[CategoryName]" VisibleIndex="4"> <PropertiesHyperLinkEdit TextField="CategoryName" DisplayFormatString="Open <b>{0}<b/>"></PropertiesHyperLinkEdit> </dx:GridViewDataHyperLinkColumn> <dx:GridViewDataHyperLinkColumn FieldName="HyperLinkColumn2" UnboundType="String" UnboundExpression="'?id='+[CategoryID]+'&name='+[CategoryName]" VisibleIndex="4"> <PropertiesHyperLinkEdit TextField="CategoryName" DisplayFormatString="Open <b>{0}<b/>" NavigateUrlFormatString="Default2.aspx{0}"></PropertiesHyperLinkEdit> </dx:GridViewDataHyperLinkColumn> </Columns> </dx:ASPxGridView> <asp:AccessDataSource ID="ads" runat="server" DataFile="~/App_Data/nwind.mdb" SelectCommand="SELECT * FROM [Categories]"></asp:AccessDataSource> </form> </body> </html>
Solution/Default2.aspx.cs(vb)
C#
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Solution { public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.QueryString["id"])) Response.Write("ID = " + Request.QueryString["id"]); if (!string.IsNullOrEmpty(Request.QueryString["name"])) Response.Write("<br/>Category Name = " + Request.QueryString["name"]); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.