Skip to content

DevExpress-Examples/mvc-gridview-display-hyperlink-in-templated-column

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET MVC - How to display a hyperlink in a templated column

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)

Files to Look At:

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)