This example demonstrates how to create a GridViewDataHyperLinkColumn whose URL depends on several column values.
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
- Default.aspx (VB: Default.aspx)
- Default2.aspx.cs (VB: Default2.aspx.vb)
Documentation
More Examples
- How to use a hyperlink whose argument depends on several cell values in the ASPxGridView
- ASPxGridView - How to display a popup using GridViewDataHyperLinkColumn and its NavigateUrlFormatString property
- How to show popup by clicking a hyperlink in grid column's DataItemTemplate
- How to create and configure a HyperLink column at runtime
- How to change styles for a hyperlink column
Example Code
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>
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"]);
}
}
}