Skip to content

DevExpress-Examples/asp-net-web-forms-grid-display-images

Repository files navigation

Grid View for ASP.NET Web Forms - How to display an image in a grid cell

This example demonstrates how to load an image into a cell based on another cell value.

Implementation Details

The Image column declares a DataItemTemplate that contains the img element.

<dx:GridViewDataColumn Caption="Image (Template)" >
    <DataItemTemplate>
        <img id="img" runat="server" alt='Eval("Value")' src='<%# GetImageName(Eval("Value")) %>' />
    </DataItemTemplate>
</dx:GridViewDataColumn>

An image URL is determined based on the row value in the Value column.

protected string GetImageName(object dataValue) {
    string val = string.Empty;
    try {
        val = (string)dataValue;
    } catch { }

    switch(val) {
        case "attach":
            return "~/Images/attach32x32.png";
        case "back":
            return "~/Images/back32x32.png";
        default:
            return "~/Images/1x1.gif";
    }
}

Files to Review

More Examples

Does this example address your development requirements/objectives?

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

About

.NET, ASP.NET Web Forms, ASPxGridView

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •