This example demonstrates how to create a grid column that displays hyperlinks.
Follow the steps below to create the HyperLink column at runtime.
- Create an object of the GridViewDataHyperLinkColumn type.
- Use the object's PropertiesHyperLinkEdit property to customize the hyperlink-related settings.
- 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();
}
}
- Default.aspx.cs (VB: Default.aspx.vb)
- Default.aspx (VB: Default.aspx)
(you will be redirected to DevExpress.com to submit your response)