I have gridview
in code I dynamiclly added header rows
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
DataClasses1DataContext kori = new DataClasses1DataContext();
var kor = (from k in kori.Korisnicis where Session["log"].ToString() == k.korisnickoime select k).FirstOrDefault();
if (e.Row.RowType == DataControlRowType.Header)
{
// dodavanje extra reda u heder
GridViewRow header3 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
GridViewRow header4= new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
GridViewRow header = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
GridViewRow header1 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
GridViewRow header2= new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
GridViewRow header0 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell cel3 = new TableCell();
cel3.ColumnSpan = 4;
cel3.Text = "ziro racun : 160-79750-28";
cel3.HorizontalAlign = HorizontalAlign.Justify;
header3.Cells.Add(cel3);
GridView1.Controls[0].Controls.AddAt(0, header3);
TableCell cel4 = new TableCell();
cel4.ColumnSpan = 4;
cel4.Text = "Pib 101735494 ";
cel4.HorizontalAlign = HorizontalAlign.Justify;
header4.Cells.Add(cel4);
GridView1.Controls[0].Controls.AddAt(0, header4);
TableCell cel = new TableCell();
cel.ColumnSpan = 2;
cel.Text = "11000 Beograd ";
cel.HorizontalAlign = HorizontalAlign.Justify;
header.Cells.Add(cel);
TableCell celgr = new TableCell();
celgr.ColumnSpan = 2;
celgr.Text = kor.grad;
celgr.HorizontalAlign = HorizontalAlign.Justify;
header.Cells.Add(celgr);
GridView1.Controls[0].Controls.AddAt(0, header);
TableCell cel1 = new TableCell();
cel1.ColumnSpan = 2;
cel1.Text = "109 nova 18";
cel1.HorizontalAlign = HorizontalAlign.Justify;
TableCell celadr = new TableCell();
celadr.ColumnSpan = 2;
celadr.Text = kor.adresa;
celadr.HorizontalAlign = HorizontalAlign.Justify;
header1.Cells.Add(cel1);
header1.Cells.Add(celadr);
GridView1.Controls[0].Controls.AddAt(0, header1);
TableCell cel2 = new TableCell();
cel2.ColumnSpan = 2;
cel2.Text = "verona company";
cel2.HorizontalAlign = HorizontalAlign.Justify;
TableCell celk = new TableCell();
celk.ColumnSpan = 2;
celk.Text = kor.ime+" "+kor.prezime + brRac ;
celk.HorizontalAlign = HorizontalAlign.Justify;
header2.Cells.Add(cel2);
header2.Cells.Add(celk);
GridView1.Controls[0].Controls.AddAt(0, header2);
TableCell celprod = new TableCell();
celprod.ColumnSpan = 2;
celprod.Text = "prodavac";
celprod.HorizontalAlign = HorizontalAlign.Justify;
TableCell celkup = new TableCell();
celkup.ColumnSpan = 2;
celkup.Text = "kupac";
header0.Cells.Add(celprod);
header0.Cells.Add(celkup);
celkup.HorizontalAlign = HorizontalAlign.Justify;
GridView1.Controls[0].Controls.AddAt(0, header0);
}
{
DataClasses1DataContext kori = new DataClasses1DataContext();
var kor = (from k in kori.Korisnicis where Session["log"].ToString() == k.korisnickoime select k).FirstOrDefault();
if (e.Row.RowType == DataControlRowType.Header)
{
// dodavanje extra reda u heder
GridViewRow header3 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
GridViewRow header4= new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
GridViewRow header = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
GridViewRow header1 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
GridViewRow header2= new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
GridViewRow header0 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell cel3 = new TableCell();
cel3.ColumnSpan = 4;
cel3.Text = "ziro racun : 160-79750-28";
cel3.HorizontalAlign = HorizontalAlign.Justify;
header3.Cells.Add(cel3);
GridView1.Controls[0].Controls.AddAt(0, header3);
TableCell cel4 = new TableCell();
cel4.ColumnSpan = 4;
cel4.Text = "Pib 101735494 ";
cel4.HorizontalAlign = HorizontalAlign.Justify;
header4.Cells.Add(cel4);
GridView1.Controls[0].Controls.AddAt(0, header4);
TableCell cel = new TableCell();
cel.ColumnSpan = 2;
cel.Text = "11000 Beograd ";
cel.HorizontalAlign = HorizontalAlign.Justify;
header.Cells.Add(cel);
TableCell celgr = new TableCell();
celgr.ColumnSpan = 2;
celgr.Text = kor.grad;
celgr.HorizontalAlign = HorizontalAlign.Justify;
header.Cells.Add(celgr);
GridView1.Controls[0].Controls.AddAt(0, header);
TableCell cel1 = new TableCell();
cel1.ColumnSpan = 2;
cel1.Text = "109 nova 18";
cel1.HorizontalAlign = HorizontalAlign.Justify;
TableCell celadr = new TableCell();
celadr.ColumnSpan = 2;
celadr.Text = kor.adresa;
celadr.HorizontalAlign = HorizontalAlign.Justify;
header1.Cells.Add(cel1);
header1.Cells.Add(celadr);
GridView1.Controls[0].Controls.AddAt(0, header1);
TableCell cel2 = new TableCell();
cel2.ColumnSpan = 2;
cel2.Text = "verona company";
cel2.HorizontalAlign = HorizontalAlign.Justify;
TableCell celk = new TableCell();
celk.ColumnSpan = 2;
celk.Text = kor.ime+" "+kor.prezime + brRac ;
celk.HorizontalAlign = HorizontalAlign.Justify;
header2.Cells.Add(cel2);
header2.Cells.Add(celk);
GridView1.Controls[0].Controls.AddAt(0, header2);
TableCell celprod = new TableCell();
celprod.ColumnSpan = 2;
celprod.Text = "prodavac";
celprod.HorizontalAlign = HorizontalAlign.Justify;
TableCell celkup = new TableCell();
celkup.ColumnSpan = 2;
celkup.Text = "kupac";
header0.Cells.Add(celprod);
header0.Cells.Add(celkup);
celkup.HorizontalAlign = HorizontalAlign.Justify;
GridView1.Controls[0].Controls.AddAt(0, header0);
}
I am use next code to export gridview to pdf Its works but I can't positioning gridview on pdf document It is always on the left top corner positon If I use other code and create table and table write to doc I can't got header rows from gridview
GridView1.DataBind();
StringWriter stringWriter2 = new StringWriter();
HtmlTextWriter htmlTextWriter2 = new HtmlTextWriter(stringWriter2);
GridView1.RenderControl(htmlTextWriter2);
StringReader sr2 = new StringReader(stringWriter2.ToString());
Document doc2 = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
PdfWriter writer2 = PdfWriter.GetInstance(doc2, Response.OutputStream);
doc2.Open();
XMLWorkerHelper.GetInstance().ParseXHtml(writer2, doc2, sr2);
doc2.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Racun.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter stringWriter2 = new StringWriter();
HtmlTextWriter htmlTextWriter2 = new HtmlTextWriter(stringWriter2);
GridView1.RenderControl(htmlTextWriter2);
StringReader sr2 = new StringReader(stringWriter2.ToString());
Document doc2 = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
PdfWriter writer2 = PdfWriter.GetInstance(doc2, Response.OutputStream);
doc2.Open();
XMLWorkerHelper.GetInstance().ParseXHtml(writer2, doc2, sr2);
doc2.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Racun.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Thanks in advance
miroslav nikolicPosted Nov 27, 2014, 5:07 PM
Thank you in advance one more time
Vithal WadjePosted Nov 10, 2014, 1:29 PM
Export GridView to PDF Using Asp.net C#