Skip to content

DevExpress-Examples/asp-net-web-forms-grid-create-hyperlink-column-at-runtime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET Web Forms - How to create and configure a HyperLink column at runtime

This example demonstrates how to create a grid column that displays hyperlinks.

Hyperlink Column

Follow the steps below to create the HyperLink column at runtime.

  1. Create an object of the GridViewDataHyperLinkColumn type.
  2. Use the object's PropertiesHyperLinkEdit property to customize the hyperlink-related settings.
  3. Call the Add or Insert method to add the newly created column to the grid column collection.
public void PopulateColumns() {
    // ...
    GridViewDataHyperLinkColumn colItemName = new GridViewDataHyperLinkColumn();
    colItemName.FieldName = "ItemName";
    colItemName.PropertiesHyperLinkEdit.NavigateUrlFormatString = "~/details.aspx?Device={0}";
    colItemName.PropertiesHyperLinkEdit.TextFormatString = "Get details about device {0}";
    colItemName.PropertiesHyperLinkEdit.TextField = "ItemName";
    ASPxGridView1.Columns.Add(colItemName);
}

Columns are created on the first Page_Init event call. Then, the grid automatically recreates columns from the view state on a callback or post back.

protected void Page_Init(object sender, EventArgs e) {
    ASPxGridView1.KeyFieldName = "ID";
    ASPxGridView1.DataSource = GetData();
    if (!IsPostBack && !IsCallback) {
        PopulateColumns();
        ASPxGridView1.DataBind();
    }
}

Files to Review