I want to generate QR Code in Gridview In rawdataBound Event
QR Code Generate in RowdataBound in Gridview in Asp.net
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
I want to generate QR Code in Gridview In rawdataBound Event
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted Dec 23, 2022, 5:40 AM EST
I hope you have a placeholder control inside your Gridview itemtemplate where you want to add QRCode
now on RowDataBound event
if (e.Row.RowType == DataControlRowType.DataRow) { //Find the PlaceHolder control. PlaceHolder plBarcode= (e.Row.FindControl("plBarCode") as PlaceHolder); int index = e.Row.RowIndex; string code = "testabc"+index; QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q); System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image(); imgBarCode.Height = 150; imgBarCode.Width = 150; using (Bitmap bitMap = qrCode.GetGraphic(20)) { using (MemoryStream ms = new MemoryStream()) { bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] byteImage = ms.ToArray(); imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage); } plBarCode.Controls.Add(imgBarCode); } }Sachin SinghRank #66 · 26.2K reputationPosted Dec 23, 2022, 7:34 AM EST