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.
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.
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
(you will be redirected to DevExpress.com to submit your response)