Hello guys,
I need help for my webpage.
I made a SQL database which include my data and I created 2 pages that I and my customer can look data in Gridview.
One of my client asked me that she wants to select data and download as list from gridview in excel or pdf.
I succeeded to make it one of page which is main page that I can add new data from that page.
But when I tried same code to add in customer page there has error that I can not find solution.
![Name: Capture.jpg
Views: 12
Size: 17.8 KB]()
Here is some part from my customer.aspx included gridview part.
And here is my pdf codes.
Is there anyone that who can help me.
I need help for my webpage.
I made a SQL database which include my data and I created 2 pages that I and my customer can look data in Gridview.
One of my client asked me that she wants to select data and download as list from gridview in excel or pdf.
I succeeded to make it one of page which is main page that I can add new data from that page.
But when I tried same code to add in customer page there has error that I can not find solution.
Here is some part from my customer.aspx included gridview part.
Code:
<script type="text/javascript">
var gridViewId = '#<%= GridView1.ClientID %>';
function checkAll(selectAllCheckbox) {
//get all checkbox and select it
$('td :checkbox', gridViewId).prop("checked", selectAllCheckbox.checked);
}
function unCheckSelectAll(selectCheckbox) {
//if any item is unchecked, uncheck header checkbox as also
if (!selectCheckbox.checked)
$('th :checkbox', gridViewId).prop("checked", cbSelectAll.checked = "");
}
</script>
<asp:panel ID="panel2" runat="server" style="width:76%; float:right; margin-bottom:0px; margin-top:1px">
<div style ="background-color:lightgray; border-color:black; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px;
height:40px;width:100%; margin:0;padding:0">
<table cellspacing="0" cellpadding = "0" rules="all" id="tblHeader" style="font-family:Arial;font-size:10pt;color:black; border:none;
border-collapse:collapse;height:100%;width:100%;float:left; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">
<tr>
<td style="width:17px; border:none"></td>
<td style="width:20px; border:none"><asp:CheckBox ID="cbSelectAll" runat="server" onclick="checkAll(this);" ></asp:CheckBox></td>
<td style ="width:63px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Rapor Tarihi</td>
<td style ="width:64px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Rapor Numarası</td>
<td style ="width:93px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Kurum Adı</td>
<td style ="width:90px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Cihazın Markası</td>
<td style ="width:75px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Cihazın Modeli</td>
<td style ="width:92px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Seri Numarası</td>
<td style ="width:64px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Servis Mühendisi</td>
<td style ="width:50px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Servis Nedeni</td>
<td style ="width:50px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Cihazın Durumu</td>
<td style ="width:112px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Açıklama</td>
<td style ="width:128px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Yapılan İşlemler</td>
<td style="width:50px; border:none"></td>
</tr>
</table>
</div>
<div class="mostly-customized-scrollbar" style="height:470px; border:none; width:96.8%; margin:0;padding:0;">
<asp:GridView ID="GridView1" runat="server" Width="100%" BorderStyle="Solid" borderwidth="1px" BorderColor="black" AlternatingRowStyle-BorderColor="black" AlternatingRowStyle-BorderStyle="Solid" AlternatingRowStyle-BorderWidth="1px" HorizontalAlign="Left" AutoGenerateColumns = "False" Font-Names = "Helvetica" ShowHeader = "False"
Font-Size = "12px" OnRowDataBound="OnRowDataBound" Height="40px" charset="CP1254" CurrentSortField="Rapor Numarası" CurrentSortDirection="DESC">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="cbSelect" runat="server" onclick="unCheckSelectAll(this);" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Rapor Tarihi" HeaderText="Rapor Tarihi" SortExpression="Rapor Tarihi" ItemStyle-Width="7%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
<ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="7%" />
</asp:BoundField>
<asp:BoundField DataField="Rapor Numarası" HeaderText="Rapor Numarası" SortExpression="Rapor Numarası" ItemStyle-Width="7%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
<ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="7%" />
</asp:BoundField>
<asp:BoundField DataField="Kurum Adı" HeaderText="Kurum Adı" SortExpression="Kurum Adı" ItemStyle-Width="10%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
<ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="10%" />
</asp:BoundField>
<asp:BoundField DataField="Cihazın Markası" HeaderText="Cihazın Markası" SortExpression="Cihazın Markası" ItemStyle-Width="10%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
<ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="10%" />
</asp:BoundField>
<asp:BoundField DataField="Cihazın Modeli" HeaderText="Cihazın Modeli" SortExpression="Cihazın Modeli" ItemStyle-Width="8%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
<ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="8%" />
</asp:BoundField>
<asp:BoundField DataField="Seri Numarası" HeaderText="Seri Numarası" SortExpression="Seri Numarası" ItemStyle-Width="10%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
<ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="10%"/>
</asp:BoundField>
<asp:BoundField DataField="Servis Mühendisi" HeaderText="Servis Mühendisi" SortExpression="Servis Mühendisi" ItemStyle-Width="7%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
<ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="7%" />
</asp:BoundField>
<asp:BoundField DataField="Servis Nedeni" HeaderText="Servis Nedeni" SortExpression="Servis Nedeni" ItemStyle-Width="5%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
<ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="5%" />
</asp:BoundField>
<asp:BoundField DataField="Cihazın Durumu" HeaderText="Cihazın Durumu" SortExpression="Cihazın Durumu" ItemStyle-Width="5%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
<ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="5%" />
</asp:BoundField>
<asp:BoundField DataField="Açıklama" HeaderText="Açıklama" SortExpression="Açıklama" ItemStyle-Width="13%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
<ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="13%" />
</asp:BoundField>
<asp:BoundField DataField="Yapılan İşlemler" HeaderText="Yapılan İşlemler" SortExpression="Yapılan İşlemler" ItemStyle-Width="13%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
<ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="13%" />
</asp:BoundField>
<asp:CommandField ShowSelectButton="True" ItemStyle-Width="4%" ItemStyle-ForeColor="#191970" SelectText="Seç" ItemStyle-BorderStyle="None">
<ItemStyle ForeColor="MidnightBlue" Width="4%" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" />
</asp:CommandField>
</Columns>
</asp:GridView>
</div>
</asp:panel>Code:
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
Protected Sub ImageButton4_Click(sender As Object, e As ImageClickEventArgs) Handles ImageButton4.Click
Dim Helvetica = iTextSharp.text.pdf.BaseFont.CreateFont("Helvetica", "CP1254", iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED)
Dim t1 = New iTextSharp.text.Font(Helvetica, 24, FontStyle.Bold)
Dim t2 = New iTextSharp.text.Font(Helvetica, 10, FontStyle.Regular)
Dim t3 = New iTextSharp.text.Font(Helvetica, 12, FontStyle.Bold)
Using a1 As StringWriter = New StringWriter()
Using a2 As HtmlTextWriter = New HtmlTextWriter(a1)
GridView1.Columns(0).Visible = False
GridView1.Columns(12).Visible = False
For Each r1 As GridViewRow In GridView1.Rows
If r1.RowType = DataControlRowType.DataRow Then
r1.Visible = (TryCast(r1.FindControl("cbSelect"), CheckBox)).Checked
End If
Next
GridView1.RenderControl(a2)
Dim a3 As StringReader = New StringReader(a1.ToString())
Dim cusdoc As Document = New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 10.0F)
cusdoc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate())
Dim w1 As PdfWriter = PdfWriter.GetInstance(cusdoc, Response.OutputStream)
cusdoc.Open()
Dim logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/images/farmakim logo.png"))
logo.SpacingAfter = 0
logo.ScaleAbsolute(20, 140)
Dim Empty As New PdfPTable(3)
Empty.SetWidths(New Integer() {350, 700, 350})
Empty.DefaultCell.BorderColor = BaseColor.WHITE
Empty.WidthPercentage = 100.0F
Empty.SpacingBefore = 100
Empty.DefaultCell.VerticalAlignment = VerticalAlign.Middle
Empty.HorizontalAlignment = HorizontalAlign.Center
Empty.DefaultCell.FixedHeight = 40
Empty.AddCell(logo)
Empty.AddCell(New Phrase("Servis Raporları Özeti", t1))
Empty.AddCell(New Phrase("www.farmakim.com.tr", t3))
cusdoc.Add(Empty)
Dim table1 As New PdfPTable(11)
table1.SetWidths(New Integer() {69, 69, 96, 96, 78, 87, 78, 50, 50, 124, 124})
table1.WidthPercentage = 100.0F
table1.DefaultCell.BorderColor = BaseColor.BLACK
table1.DefaultCell.BorderWidth = 1.5
table1.DefaultCell.VerticalAlignment = VerticalAlign.Middle
table1.HorizontalAlignment = 0
table1.DefaultCell.FixedHeight = 26
table1.AddCell(New Phrase("Rapor Tarihi", t2))
table1.AddCell(New Phrase("Rapor Numarası", t2))
table1.AddCell(New Phrase("Kurum Adı", t2))
table1.AddCell(New Phrase("Cihazın Markası", t2))
table1.AddCell(New Phrase("Cihazın Modeli", t2))
table1.AddCell(New Phrase("Seri Numarası", t2))
table1.AddCell(New Phrase("Servis Mühendisi", t2))
table1.AddCell(New Phrase("Servis Nedeni", t2))
table1.AddCell(New Phrase("Cihazın Durumu", t2))
table1.AddCell(New Phrase("Açıklama", t2))
table1.AddCell(New Phrase("Yapılan İşlemler", t2))
table1.AddCell(New Phrase("", t2))
cusdoc.Add(table1)
iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(w1, cusdoc, a3)
cusdoc.Close()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=Farmakim - " + Now + ".pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Write(cusdoc)
Response.[End]()
End Using
End Using
End Sub