I want to print all QR Code which is bind in gridview ,
i want to clich click a button and print all QR Code In Once click.
The below image is gridview data bind in asp.net

I want to print all QR Code which is bind in gridview ,
i want to clich click a button and print all QR Code In Once click.
The below image is gridview data bind in asp.net

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
Rajkiran SwainRank #165 · 14.4K reputationPosted May 16, 2023, 3:23 AM EDT
using System.Drawing.Printing; using ZXing; private void BtnPrint_Click(object sender, EventArgs e) { // Retrieve data from the gridview foreach (GridViewRow row in GridView1.Rows) { // Get the data for each row (e.g., QR code value) string qrCodeValue = row.Cells[0].Text; // Generate QR code image BarcodeWriter barcodeWriter = new BarcodeWriter(); barcodeWriter.Format = BarcodeFormat.QR_CODE; barcodeWriter.Options = new ZXing.Common.EncodingOptions { Width = 200, Height = 200 }; Bitmap qrCodeImage = barcodeWriter.Write(qrCodeValue); // Print the QR code image PrintDocument printDoc = new PrintDocument(); printDoc.PrintPage += (s, args) => { args.Graphics.DrawImage(qrCodeImage, args.MarginBounds); args.HasMorePages = false; }; printDoc.Print(); } }Sandeep KumarRank #1,642 · 937 reputationPosted May 16, 2023, 3:55 AM EDT
Always Showing ""(Blank) thst's why not working
string qrCodeValue = row.Cells[0].Text;
Rajkiran SwainRank #165 · 14.4K reputationPosted May 16, 2023, 4:23 AM EDT
private void BtnPrint_Click(object sender, EventArgs e) { // Retrieve data from the gridview foreach (GridViewRow row in GridView1.Rows) { // Get the data for each row (e.g., QR code value) string qrCodeValue = row.Cells[1].Text; // Use the correct column index // Generate QR code image BarcodeWriter barcodeWriter = new BarcodeWriter(); barcodeWriter.Format = BarcodeFormat.QR_CODE; barcodeWriter.Options = new ZXing.Common.EncodingOptions { Width = 200, Height = 200 }; Bitmap qrCodeImage = barcodeWriter.Write(qrCodeValue); // Print the QR code image PrintDocument printDoc = new PrintDocument(); printDoc.PrintPage += (s, args) => { args.Graphics.DrawImage(qrCodeImage, args.MarginBounds); args.HasMorePages = false; }; printDoc.Print(); } }Sandeep KumarRank #1,642 · 937 reputationPosted May 16, 2023, 4:42 AM EDT
row.Cells[1].Text; // Use the correct column index
i used this but still it has ""(blank) value
Amit MohantyRank #112 · 20K reputationPosted May 16, 2023, 4:48 AM EDT
Check this
protected void btnPrint_Click(object sender, EventArgs e) { // Loop through all rows in the gridview for (int i = 0; i { args.Graphics.DrawImage(imgQRCode.Image, new Point(0, 0)); }; pd.Print(); } }Sandeep KumarRank #1,642 · 937 reputationPosted May 16, 2023, 4:59 AM EDT
All Qr Code should be in one page
Amit MohantyRank #112 · 20K reputationPosted May 16, 2023, 5:10 AM EDT
Try this
protected void btnPrint_Click(object sender, EventArgs e) { List qrCodeImages = GetQRCodeImages(); // Function to retrieve QR code images from gridview int numColumns = 4; // Number of columns in the layout int numRows = (int)Math.Ceiling((double)qrCodeImages.Count / numColumns); // Number of rows in the layout int qrCodeWidth = 200; // Width of each QR code image int qrCodeHeight = 200; // Height of each QR code image int combinedImageWidth = qrCodeWidth * numColumns; // Width of the combined image int combinedImageHeight = qrCodeHeight * numRows; // Height of the combined image Bitmap combinedImage = new Bitmap(combinedImageWidth, combinedImageHeight); using (Graphics g = Graphics.FromImage(combinedImage)) { for (int i = 0; i { args.Graphics.DrawImage(combinedImage, new Point(0, 0)); }; pd.Print(); } private List GetQRCodeImages() { List qrCodeImages = new List(); foreach (GridViewRow row in GridView1.Rows) { Image imgQRCode = (Image)row.FindControl("imgQRCode"); // Convert the Image control to a Bitmap object Bitmap qrCodeImage = new Bitmap(imgQRCode.Image); qrCodeImages.Add(qrCodeImage); } return qrCodeImages; }Sandeep KumarRank #1,642 · 937 reputationPosted May 16, 2023, 6:13 AM EDT
i am using PlaceHolder control in place of Image in gridview ItemTemplate
Amit MohantyRank #112 · 20K reputationPosted May 16, 2023, 6:59 AM EDT
For Placeholder control:
private List GetQRCodeImages() { List qrCodeImages = new List(); foreach (GridViewRow row in GridView1.Rows) { Placeholder placeholderQRCode = (Placeholder)row.FindControl("placeholderQRCode"); // Create a bitmap object and draw the contents of the placeholder onto it Bitmap qrCodeImage = new Bitmap(placeholderQRCode.Width, placeholderQRCode.Height); placeholderQRCode.RenderControl(new HtmlTextWriter(new StringWriter())); using (Graphics graphics = Graphics.FromImage(qrCodeImage)) { IntPtr hdc = graphics.GetHdc(); placeholderQRCode.RenderControl(new HtmlTextWriter(new HtmlTextWriter(new IntPtr(hdc)))); graphics.ReleaseHdc(hdc); } qrCodeImages.Add(qrCodeImage); } return qrCodeImages; }Sandeep KumarRank #1,642 · 937 reputationPosted May 16, 2023, 7:35 AM EDT
This line error showing
Bitmap qrCodeImage = new Bitmap(placeholderQRCode.Width, placeholderQRCode.Height);
Rajkiran SwainRank #165 · 14.4K reputationPosted May 16, 2023, 8:26 AM EDT
private void BtnPrint_Click(object sender, EventArgs e) { // Create a bitmap to hold all QR codes int qrCodeWidth = 200; // Width of each QR code int qrCodeHeight = 200; // Height of each QR code int spacing = 10; // Spacing between QR codes int rowCount = GridView1.Rows.Count; // Number of rows in the GridView int columnCount = 4; // Number of QR codes to be displayed in each row (adjust as needed) int totalWidth = columnCount * qrCodeWidth + (columnCount - 1) * spacing; int totalHeight = ((rowCount - 1) / columnCount + 1) * qrCodeHeight + ((rowCount - 1) / columnCount) * spacing; Bitmap combinedImage = new Bitmap(totalWidth, totalHeight); // Retrieve data from the GridView and generate QR codes using (Graphics graphics = Graphics.FromImage(combinedImage)) { int x = 0; int y = 0; int counter = 0; foreach (GridViewRow row in GridView1.Rows) { // Get the data for each row (e.g., QR code value) string qrCodeValue = row.Cells[1].Text; // Use the correct column index // Generate QR code image BarcodeWriter barcodeWriter = new BarcodeWriter(); barcodeWriter.Format = BarcodeFormat.QR_CODE; barcodeWriter.Options = new ZXing.Common.EncodingOptions { Width = qrCodeWidth, Height = qrCodeHeight }; Bitmap qrCodeImage = barcodeWriter.Write(qrCodeValue); // Draw the QR code image on the combined image graphics.DrawImage(qrCodeImage, new Rectangle(x, y, qrCodeWidth, qrCodeHeight)); // Move to the next position x += qrCodeWidth + spacing; counter++; // Move to the next row if necessary if (counter % columnCount == 0) { x = 0; y += qrCodeHeight + spacing; } } } // Print the combined QR code image PrintDocument printDoc = new PrintDocument(); printDoc.PrintPage += (s, args) => { args.Graphics.DrawImage(combinedImage, args.MarginBounds); args.HasMorePages = false; }; printDoc.Print(); }Amit MohantyRank #112 · 20K reputationPosted May 16, 2023, 9:10 AM EDT
Use this
Bitmap qrCodeImage = new Bitmap(200, 200);Deepak RawatRank #646 · 3.7K reputationPosted Jun 6, 2023, 6:02 AM EDT
here is code you can try:
protected void PrintButton_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in YourGridView.Rows)
{
// Access data associated with each row
string qrCodeData = row.Cells[0].Text; // Assuming QR Code data is in the first column
// Generate QR Code for each row's data
Bitmap qrCodeImage = GenerateQRCode(qrCodeData); // Use your QR Code generator function
// Print the QR Code image
PrintQRCode(qrCodeImage); // Implement the printing logic
// Dispose the QR Code image to free resources
qrCodeImage.Dispose();
}
}