473,327 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Export Gridview Table to PDF with REPEAT TABLE HEADER

ayakamacy
Language: ASP.net / VB.net
Platform: Visual Studio 2010 with ASP.net
Technology: Used in ASP.net

-------------

Right now, I'm working with my report of of how to export Gridview Table with repeat table header on the next page.

can someone teach me how to do that.

here's my ASP.NET code:

Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="gv" runat="server" BackColor="White" BorderColor="#336666" 
  2.     BorderStyle="Double" BorderWidth="3px" CellPadding="4" 
  3.     Font-Names = "Arial" style="text-align: center" 
  4.     EmptyDataText="No Records Found." GridLines="Horizontal">
  5.     <FooterStyle BackColor="White" ForeColor="#333333" />
  6.     <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" 
  7.         BorderStyle="Solid" />
  8.     <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
  9.     <RowStyle BackColor="White" ForeColor="#333333" />
  10.     <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
  11.     <SortedAscendingCellStyle BackColor="#F7F7F7" />
  12.     <SortedAscendingHeaderStyle BackColor="#487575" />
  13.     <SortedDescendingCellStyle BackColor="#E5E5E5" />
  14.     <SortedDescendingHeaderStyle BackColor="#275353" />
  15. </asp:GridView>
  16.  
VB.NET codes:

Expand|Select|Wrap|Line Numbers
  1. Private Sub LoadMachineSearch()
  2.     Using con As New SqlConnection(ConStrX)
  3.         Using cmd As New SqlCommand("SELECT OVERALL_SUPPLIES.QRCode as [QR CODE], OVERALL_SUPPLIES.ItemCode as [ITEM CODE], OVERALL_SUPPLIES.ItemName as [ITEM NAME], OVERALL_SUPPLIES.Specification as [SPECIFICATION], OVERALL_SUPPLIES.MinQty as [MIN QTY], OVERALL_SUPPLIES.UnitOfMeasure as [UM], OVERALL_SUPPLIES.Currency as [CCY], OVERALL_SUPPLIES.UnitPrice as [UPRICE], OVERALL_SUPPLIES.BIqty as [BEG QTY], OVERALL_SUPPLIES.BIamount as [BEG AMT], OVERALL_SUPPLIES.Rqty as [RCV QTY], OVERALL_SUPPLIES.Ramount as [RCV AMT], IssuanceRecords.IssuedQty as [ISSUED QTY], IssuanceRecords.IssuedAmount as [ISSUED AMT], OVERALL_SUPPLIES.AAqty as [ADJ/ALLOC QTY], OVERALL_SUPPLIES.AAamount as [ADJ/ALLOC AMT], OVERALL_SUPPLIES.EIqty as [ENDING QTY], OVERALL_SUPPLIES.EIamount as [ENDING AMT], OVERALL_SUPPLIES.AIqty as [ACTL QTY], OVERALL_SUPPLIES.AIamount as [ACTL AMT], OVERALL_SUPPLIES.Dqty as [DIFF QTY], OVERALL_SUPPLIES.Damount as [DIFF AMT] FROM IssuanceRecords INNER JOIN OVERALL_SUPPLIES ON OVERALL_SUPPLIES.QRCode = IssuanceRecords.QRCode AND OVERALL_SUPPLIES.MonthYear = IssuanceRecords.MonthYear AND OVERALL_SUPPLIES.ItemCode = IssuanceRecords.ItemCode WHERE OVERALL_SUPPLIES.MonthYear = '32016'")
  4.             Using sda As New SqlDataAdapter()
  5.                 cmd.Connection = con
  6.                 sda.SelectCommand = cmd
  7.                 Using dt As New DataTable()
  8.                     sda.Fill(dt)
  9.                     gv.DataSource = dt
  10.                     gv.DataSourceID = Nothing
  11.                     gv.DataBind()
  12.                 End Using
  13.             End Using
  14.         End Using
  15.     End Using
  16. End Sub
  17.  
Expand|Select|Wrap|Line Numbers
  1. Protected Sub btnPDF_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPDF.Click
  2. Response.ContentType = "application/pdf"
  3. Response.AddHeader("content-disposition",
  4. "attachment;filename=GridViewExport.pdf")
  5. Response.Cache.SetCacheability(HttpCacheability.NoCache)
  6. Dim sw As New StringWriter()
  7. Dim hw As New HtmlTextWriter(sw)
  8. gv.AllowPaging = False
  9. LoadMachineSearch()
  10. gv.RenderControl(hw)
  11.  
  12. Dim sr As New StringReader(sw.ToString())
  13. Dim pdfDoc As New Document(New RectangleReadOnly(1587, 1122), 10.0F, 10.0F, 10.0F, 0.0F)
  14. Dim htmlparser As New HTMLWorker(pdfDoc)
  15. PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
  16. pdfDoc.Open()
  17. htmlparser.Parse(sr)
  18. pdfDoc.Close()
  19. Response.Write(pdfDoc)
  20. Response.End()
  21. End Sub
  22.  
Attached Images
File Type: jpg RepeatHeader.jpg (76.9 KB, 295 views)
Mar 31 '16 #1
1 2073
madankarmukta
308 256MB
I would suggest to create just a report (SSRS) and export it as a pdf.

There is no need to keep this as a part of ASP.Net GridView

Please let me know if this isn't suffice the actual requirement
Apr 3 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: JJ | last post by:
Hi, usually, I'm not using MS servers, but I have a big problem with a Access table. I should create a web application for a Historical Dipartment. They have create a populated a Access...
0
by: weiwei | last post by:
Hi, I have a table in View and I want to export that table into the excel sheet. I know that I can export file in Tables where there is a all task function, however, I cannt' find that function...
4
by: JJ | last post by:
Hi, usually, I'm not using MS servers, but I have a big problem with a Access table. I should create a web application for a Historical Dipartment. They have created a populated a Access...
3
by: bwhite | last post by:
I have a temp table with one row of data that I need to export into Excel. I created the export to create the xls file as follows ... Dim FileName FileName = !! DoCmd.SetWarnings False...
1
by: keithb | last post by:
Is there a way to make a GridView header row invisible? Thanks, Keith
2
by: dfdavis.mtu | last post by:
I have a table that I dynamically fill with data from a database for medical companies to be able to determine if their patients meet certain criteria. However they want a fixed header for it so...
2
by: Burbletrack | last post by:
Hi All, Hope someone can help me... Im trying to highlight the advantages of using table variables as apposed to temp tables within single scope. My manager seems to believe that table...
3
by: =?Utf-8?B?bWFuaWthMDI=?= | last post by:
Hi, I have a GridView control in page called eventslisting which is inheriting from a MasterPage. The normal code to export to GridView does not work and gives me an error - "Control of type...
2
by: Sashi | last post by:
Hi All, I have a table from which I want to export the data as a plain text file. I exported the data using the "Export" option and selected the comma as a separator and the " as the Text...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.