can any body help me to find aa solution......it works only for only one grid.........thank u in advance
 
 
protected void Button6_Click1(object sender, EventArgs e)
{
            for (int i = 1; i <= checkcatg.Items.Count; i++)
            {
                if (checkcatg.Items[0].Selected)
                {
                    GridView1.Visible = true;
                    SqlConnection conn = new SqlConnection("server=.;database=project;uid=sa;pwd=abc;");
                    SqlCommand cmd = new SqlCommand("select * from pantsmeasurements where pant_id=(select MAX(pant_id) from pantsmeasurements)", conn);
                    DataSet ds = new DataSet();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(ds);
                    GridView1.DataSource = ds;
                    GridView1.DataBind();
                    //printpants();
                    PdfPTable pdfTable = new PdfPTable(GridView1.HeaderRow.Cells.Count);
                    foreach (GridViewRow gridViewRow in GridView1.Rows)
                    {
                        foreach (TableCell tableCell in gridViewRow.Cells)
                        {
                            PdfPCell pdfcell = new PdfPCell(new Phrase(tableCell.Text));
                            pdfTable.AddCell(pdfcell);
                        }
                    }
                    Document pdfDocument = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
                    PdfWriter.GetInstance(pdfDocument, Response.OutputStream);
                    pdfDocument.Open();
                    pdfDocument.Add(pdfTable);
                    pdfDocument.Close();
                    Response.ContentType = ("application/pdf");
                    Response.AppendHeader("content-dispostion", "attachment;filename=employees.pdf");
                    Response.Write(pdfDocument);
                    Response.Flush();
                    Response.End();
                }
                if (checkcatg.Items[1].Selected)
                {
                    GridView2.Visible = true;
                    SqlConnection conn = new SqlConnection("server=.;database=project;uid=sa;pwd=abc;");
                    SqlCommand cmd = new SqlCommand("select * from shirtsmeasurements where shirt_id=(select MAX(shirt_id) from shirtsmeasurements)", conn);
                    DataSet ds = new DataSet();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(ds);
                    GridView2.DataSource = ds;
                    GridView2.DataBind();
                    //printshirts();
                    PdfPTable pdfTable = new PdfPTable(GridView2.HeaderRow.Cells.Count);
                    foreach (GridViewRow gridViewRow in GridView2.Rows)
                    {
                        foreach (TableCell tableCell in gridViewRow.Cells)
                        {
                            PdfPCell pdfcell = new PdfPCell(new Phrase(tableCell.Text));
                            pdfTable.AddCell(pdfcell);
                        }
                    }
                    Document pdfDocument = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
                    PdfWriter.GetInstance(pdfDocument, Response.OutputStream);
                    pdfDocument.Open();
                    pdfDocument.Add(pdfTable);
                    pdfDocument.Close();
                    Response.ContentType = ("application/pdf");
                    Response.AppendHeader("content-dispostion", "attachment;filename=employees.pdf");
                    Response.Write(pdfDocument);
                    Response.Flush();
                    Response.End();
                }