locked
free QR barcode for my refno asp.net 2.0 RRS feed

  • Question

  • User-807418713 posted

    Hello

    My Gridview look like this

    ItemNam Color Qty RefNo
    Apple Red 10 R1118-001
    Mango Yellow 5 R1118-002
    Banana  Green 2 R1118-003

    I want free commerical use QR barcode and gridview should look like this below

    Thanks

    Tuesday, December 11, 2018 10:39 AM

Answers

  • User-1174608757 posted

    Hi Gopi.MCA,

    According to your description ,I have made a sample here.I suggest you to write method  in OnRowDataBound Event of Gridview .You can first get the value of RefNo,then  you can convert value  to source of QR image. Here is the code ,I hope it will help you.

    Image.aspx:

     <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
                   
    
                </asp:GridView>
            </div>
        </form>
    </body>

    Image.aspx.cs:

     protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    string sql = "select * from qr";
                    GridView1.DataSource = SqlHelper.ExecuteDataTable(sql);
                    GridView1.DataBind();
                }
            }
    
            protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    string s = e.Row.Cells[3].Text;
                    
                    QRCodeGenerator qrGenerator = new QRCodeGenerator();
                    QRCodeData qrCodeData = qrGenerator.CreateQrCode(s, QRCodeGenerator.ECCLevel.Q);
                    System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
                    imgBarCode.Width = 100;
                    QRCode qrCode = new QRCode(qrCodeData);
                    using (Bitmap qrCodeImage = qrCode.GetGraphic(20))
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                            byte[] byteImage = ms.ToArray();
                            Image img = (Image)e.Row.FindControl("Image1");
    
                            imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
                            
                        }
    
                        e.Row.Cells[3].Controls.Add(imgBarCode);
    
                    }
                        
                }
                
            }

    Result:

    Best Regards,

    Wei Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 12, 2018 9:42 AM

All replies

  • User-1174608757 posted

    Hi Gopi.MCA
    According to your description ,I have made a sample here.I suggest you to write method  in OnRowDataBound Event of Gridview .You could first get the value of RefNo,then  you could convert value  to source of QR image. Here is the code ,I hope it will help you.

    Image.aspx:
    
     <head runat="server">
    
        <title></title>
    
    </head>
    
    <body>
    
        <form id="form1" runat="server">
    
            <div>
    
                <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
    
                   
    
     
    
                </asp:GridView>
    
            </div>
    
        </form>
    
    </body>
    
    Image.aspx.cs:
    
     protected void Page_Load(object sender, EventArgs e)
    
            {
    
                if (!IsPostBack)
    
                {
    
                    string sql = "select * from qr";
    
                    GridView1.DataSource = SqlHelper.ExecuteDataTable(sql);
    
                    GridView1.DataBind();
    
                }
    
            }
    
     
    
            protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    
            {
    
                if (e.Row.RowType == DataControlRowType.DataRow)
    
                {
    
                    string s = e.Row.Cells[3].Text;
    
                   
    
                    QRCodeGenerator qrGenerator = new QRCodeGenerator();
    
                    QRCodeData qrCodeData = qrGenerator.CreateQrCode(s, QRCodeGenerator.ECCLevel.Q);
    
                    System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
    
                    imgBarCode.Width = 100;
    
                    QRCode qrCode = new QRCode(qrCodeData);
    
                    using (Bitmap qrCodeImage = qrCode.GetGraphic(20))
    
                    {
    
                        using (MemoryStream ms = new MemoryStream())
    
                        {
    
                            qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
    
                            byte[] byteImage = ms.ToArray();
    
                            Image img = (Image)e.Row.FindControl("Image1");
    
     
    
                            imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
    
                           
    
                        }
    
     
    
                        e.Row.Cells[3].Controls.Add(imgBarCode);
    
     
    
                    }
    
                       
    
                }
    
               
    
            }

    Wednesday, December 12, 2018 9:15 AM
  • User-1174608757 posted

    Hi Gopi.MCA,

    According to your description ,I have made a sample here.I suggest you to write method  in OnRowDataBound Event of Gridview .You can first get the value of RefNo,then  you can convert value  to source of QR image. Here is the code ,I hope it will help you.

    Image.aspx:

     <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
                   
    
                </asp:GridView>
            </div>
        </form>
    </body>

    Image.aspx.cs:

     protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    string sql = "select * from qr";
                    GridView1.DataSource = SqlHelper.ExecuteDataTable(sql);
                    GridView1.DataBind();
                }
            }
    
            protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    string s = e.Row.Cells[3].Text;
                    
                    QRCodeGenerator qrGenerator = new QRCodeGenerator();
                    QRCodeData qrCodeData = qrGenerator.CreateQrCode(s, QRCodeGenerator.ECCLevel.Q);
                    System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
                    imgBarCode.Width = 100;
                    QRCode qrCode = new QRCode(qrCodeData);
                    using (Bitmap qrCodeImage = qrCode.GetGraphic(20))
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                            byte[] byteImage = ms.ToArray();
                            Image img = (Image)e.Row.FindControl("Image1");
    
                            imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
                            
                        }
    
                        e.Row.Cells[3].Controls.Add(imgBarCode);
    
                    }
                        
                }
                
            }

    Result:

    Best Regards,

    Wei Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 12, 2018 9:42 AM
  • User-807418713 posted

    Hello

    How To Get This   QRCodeGenerator /  QRCodeData 

    1) Is That Anything To Add..? 2) Is this can be use commercial for free

    Thank You

    Wednesday, December 12, 2018 10:18 AM
  • User-1174608757 posted

    Hi Gopi.MCA

     You could first add reference to QRcode API ,then use the namespace of QRCoder. I am sorry I haven't post the complete codes.Here is the detail,I hope it will help you.

    Install this

    Finally in  Image.aspx.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Drawing;
    using System.IO;
    using QRCoder;
    
    namespace Talk._12._12
    {
        public partial class Image2 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    string sql = "select * from qr";
                    GridView1.DataSource = SqlHelper.ExecuteDataTable(sql);
                    GridView1.DataBind();
                }
            }
    
            protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    string s = e.Row.Cells[3].Text;
                    
                    QRCodeGenerator qrGenerator = new QRCodeGenerator();
                    QRCodeData qrCodeData = qrGenerator.CreateQrCode(s, QRCodeGenerator.ECCLevel.Q);
                    System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
                    imgBarCode.Width = 100;
                    QRCode qrCode = new QRCode(qrCodeData);
                    using (Bitmap qrCodeImage = qrCode.GetGraphic(20))
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                            byte[] byteImage = ms.ToArray();
                            Image img = (Image)e.Row.FindControl("Image1");
    
                            imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
                            
                        }
    
                        e.Row.Cells[3].Controls.Add(imgBarCode);
    
                    }
                        
                }
                
            }
        }
    }

    Wednesday, December 12, 2018 10:57 AM
  • User-807418713 posted

    Hello

    Is any other option where we can download add that dll in bin folder?

    second is this free commercial use free

    Thank you

    Wednesday, December 12, 2018 11:24 AM