Skip to content

Сreate a column template, add a binary image control to that template, and use the Bar Code Library to display a bar code image.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/asp-net-web-forms-grid-display-barcode-in-column

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET Web Forms - How to display a bar code image in a column

This example demonstrates how to create a column template, add a binary image control to that template, and use the Bar Code Library to display a bar code image.

Display a bar code image in a column

Overview

Specify a column's DataItemTemplate property, add a binary image to the template, create a bar code, and use the image's ContentBytes property to display the bar code in the column.

<dx:GridViewDataColumn>
    <DataItemTemplate>
        <dx:ASPxBinaryImage ID="BinaryImage" runat="server" OnInit="BinaryImage_Init"></dx:ASPxBinaryImage>
    </DataItemTemplate>
</dx:GridViewDataColumn>
namespace ASPxGridViewBarCode {
    public partial class Default : System.Web.UI.Page {
        protected void Page_Init(object sender, EventArgs e) {
            // ...
        }

        protected void BinaryImage_Init(object sender, EventArgs e) {
            var image = (ASPxBinaryImage)sender;
            var container = (GridViewDataItemTemplateContainer)image.NamingContainer;
            var value = container.Grid.GetRowValues(container.VisibleIndex, new string[] { "Text" });
            if (value != null)
                image.ContentBytes = GetBarCodeImage(value.ToString());
        }

        public byte[] GetBarCodeImage(string parameter) {
            BarCode barCode = new BarCode();
            // ...
            return ImageToByte(barCode.BarCodeImage);
        }

        public static byte[] ImageToByte(Image img) {
            ImageConverter converter = new ImageConverter();
            return (byte[])converter.ConvertTo(img, typeof(byte[]));
        }
    }
}

To enable this functionality, implement the Bar Code Library. To use that library in your application, you need a license for the DevExpress Office File API Subscription.

Files to Review

Does this example address your development requirements/objectives?

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

About

Сreate a column template, add a binary image control to that template, and use the Bar Code Library to display a bar code image.

Topics

Resources

License

Stars

Watchers

Forks