Articles in this section
Category / Section

How to display picture on base64 Grid column in ASP.NET Core application?

2 mins read

You can display base64 string value as an image in Grid columns by using the ‘column.template’ property and ‘queryCellInfo’ event of Grid component.

This is explained in the following sample code in which the ‘template’ property has been set with an “img” tag to the base64 column. And inside the ‘queryCellInfo’ event handler, the base64 string is bound to the column template element (i.e. <img>) to display the image.


CSHTML

 
<ejs-grid id="Grid" dataSource="@ViewBag.data" queryCellInfo="queryCellInfo" allowPaging="true">
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer ID" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="CityFlag" headerText="Flag" template="<img class='tempimg'>" width="120"></e-grid-column>
        <e-grid-column field="EmployeeID" headerText="Employee ID" width="120"></e-grid-column>
        <e-grid-column field="PayGrade" headerText="Pay Grade" width="150"></e-grid-column>
        <e-grid-column field="ShipID" headerText="Ship ID" width="150"></e-grid-column>
    </e-grid-columns>
</ejs-grid>

 

JS

<script>
    function queryCellInfo(args) { // Grid queryCellInfo event handler
        if (args.column.field == "CityFlag") {
            args.cell.querySelector('img').setAttribute('src', 'data:image/png;base64 ,' + args.data.CityFlag);
        }
    }
</script>

 

Output

Display base64 string as image in Grid column

 

Demo:

https://www.syncfusion.com/downloads/support/directtrac/general/ze/displayBase64Val-871394573


Conclusion 

I hope you enjoyed learning about how to display picture on the base64 Grid column in ASP.NET Core 

You can refer to our ASP.NET Core Grid feature tour page to know about its other groundbreaking feature representations and documentation. You can also explore our  ASP.NET Core Grid examples to understand how to present and manipulate data. 

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied