---
title: "GridView to add HyperLink column dynamically"  
description: "GridView to add HyperLink column dynamically"  
author: "Anonymous User"  
published: 2014-08-31  
updated: 2014-09-01  
canonical: https://www.mindstick.com/forum/2213/gridview-to-add-hyperlink-column-dynamically  
category: "c#"  
tags: ["c#", "gridview", "c# gridview", "add HyperLink column dynamically", "add HyperLink column dynamically in gridview", "GridView to add HyperLink column dynamically"]  
reading_time: 1 minute  

---

# GridView to add HyperLink column dynamically

We read from XML and create columns in asp [gridview](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net). Also same XML is used to create columns in a data [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap).

We [populate](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box) that data table with desired data and [bind data](https://www.mindstick.com/forum/415/how-to-bind-data-in-windows-phone-7-using-wcf-service) table to gridview using [server side](https://www.mindstick.com/forum/318/how-to-call-javascript-fuction-in-server-side) code.

I want to display hyperlink in gridview and not sure how to manage it. Since we are not using [RowDataBound](https://www.mindstick.com/forum/12667/gridview-rowdatabound-for-loop-not-working) method.

Code

[foreach](https://www.mindstick.com/forum/33870/how-parallel-foreach-works-internally) (XmlNode columnNode in columnNodes)

{

dc = new DataColumn(columnNode.Attributes["ColumnName"].Value,Type.GetType("System.String"));

dt.Columns.Add(dc);

[boundField](https://www.mindstick.com/forum/12737/get-the-value-of-a-boundfield-from-a-detailsview) = new BoundField();

boundField.HeaderText = columnNode.Attributes["ColumnDisplayName"].Value;

boundField.DataField = columnNode.Attributes["ColumnName"].Value;

boundField.SortExpression = columnNode.Attributes["ColumnName"].Value;

grdView.Columns.Add(boundField);

}

where dc is datacolumn, dt is data table and grdView is grid view.

## Replies

### Reply by Sumit Kesarwani

Hi Ashish, try this:\

linkField = new HyperLinkField();

linkField.HeaderText = columnNode.Attributes["ColumnDisplayName"].Value;

// The field you want to use as the displayed text of the hyperlink

linkField.DataTextField = columnNode.Attributes["ColumnName"].Value;

// The field(s) you want to use in the URL behind the hyperlink

linkField.DataNavigateUrlFields = new string[] { columnNode.Attributes["ColumnName"].Value };

// The formatting string for your hyperlink. Use this to build the links the way you want them.

linkField.DataNavigateUrlFormatString = "http://yourSiteName/links/{0}";

linkField.SortExpression = columnNode.Attributes["ColumnName"].Value;

grdView.Columns.Add(linkField);

\


---

Original Source: https://www.mindstick.com/forum/2213/gridview-to-add-hyperlink-column-dynamically

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
