This example illustrates how to use the MVCxGridViewColumn.SetDataItemTemplateContent method to display a hyperlink in a grid column. The hyperlink parameters (text, navigate url) are calculated based on the template's container. The code below creates the hyperlink:
C#
settings.Columns.Add(column => {
column.Caption = "Details";
column.SetDataItemTemplateContent(container => {
Html.DevExpress().HyperLink(hyperlink => {
var visibleIndex = container.VisibleIndex;
var keyValue = container.KeyValue;
var lastName = DataBinder.Eval(container.DataItem, "LastName");
hyperlink.Name = "hl" + keyValue.ToString();
hyperlink.Properties.Text = lastName.ToString();
hyperlink.NavigateUrl = Url.Action("Details", "Home", new { id = keyValue });
}).Render();
});
});
Visual Basic
settings.Columns.Add( _
Sub(column)
column.Caption = "Details"
column.SetDataItemTemplateContent( _
Sub(container)
Html.DevExpress().HyperLink( _
Sub(hl)
Dim visibleIndex = container.VisibleIndex
Dim keyValue = container.KeyValue
Dim lastName = DataBinder.Eval(container.DataItem, "LastName")
hl.Name = "hl" + keyValue.ToString()
hl.Properties.Text = lastName.ToString()
hl.NavigateUrl = Url.Action("Details", "Home", New With {.id = keyValue})
End Sub).Render()
End Sub)
End Sub)