在ASP.Net中将所选(已选中)GridView Rows导出为PDF [英] Export selected (checked) GridView Rows to PDF in ASP.Net

查看:56
本文介绍了在ASP.Net中将所选(已选中)GridView Rows导出为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法找到图片路径的一部分





Asp.net



< asp:GridView ID =GridView1runat =serverAutoGenerateColumns =FalseWidth =624pxCssClass =gridOnRowCommand =OnRowCommand

AllowPaging =TrueAllowSorting =TrueBackColor =WhiteOnRowEditing =GridView1_RowEditingOnRowCancelingEdit =GridView1_RowCancelingEdit

BorderColor =#CCCCCCBorderStyle =NoneBorderWidth =1pxCellPadding =3PageSize =5

OnRowUpdating =GridView1_RowUpdatingOnRowDeleting =GridView1_RowDeletingDataKeyNames =idOnSelectedIndexChanged =GridView1_SelectedIndexChanged>



< columns> < asp:TemplateField>

< HeaderTemplate>

< asp:CheckBox ID =chkHeaderrunat =serveronclick =CheckAll(this)/ >

< / HeaderTemplate>

< itemtemplate>

< asp:CheckBox ID =chkchildrunat =server />





< asp:BoundField DataField =idHeaderText =idSortExpression =idInsertVisible =假ReadOnly =True/>

< asp:BoundField DataField =updatedbyHeaderText =updatedbySortExpression =updatedby/>

< ; asp:BoundField DataField =usernameHeaderText =usernameSortExpression =username/>

< asp:BoundField DataField =passwordHeaderText =passwordSortExpression =password />

< asp:BoundField DataField =mailHeaderText = mailSortExpression =mail/>



< asp:BoundField DataField =imagenameHeaderText =imagenameSortExpression =imagename/>

<% - < asp:CommandField ShowEditButton =trueButtonType =imageEditImageUrl =〜/ images / delete.jpgHeaderText =Delete/> - %> ;



< asp:ImageField DataImageUrlField =uploadimageHeaderText =uploadimageControlStyle-Width =60ControlStyle-Height =100>







< asp:CommandField ShowEditButton =True/>



< asp:TemplateField HeaderText =删除>

< itemtemplate>

< asp:ImageButton ID =ImageButton2runat =serverImageUrl =〜/ images / delete.jpg

OnClientClick =return confirm('Are你确定要删除吗?')Text =删除CommandName =删除/>





< asp:TemplateField HeaderText =更新>

< itemtemplate>

< asp:LinkBut​​ton ID =linkrunat =serverText =选择CssClass =linkbuttonCommandName =选择>





< asp:TemplateField HeaderText =打印>

< itemtemplate>



< asp:ImageButton ID =excelrunat =serverImageUrl =images / excel-icon.pngOnClick =excel_Click/> < asp:ImageButton ID =pdfrunat =serverImageUrl =images / PDF-icon.pngOnClick =pdf_Click1/> < asp: ImageBu tton ID =wordrunat =serverImageUrl =images / MS-Office-2003-Word-icon.pngOnClick =word_Click/>








< asp:TemplateField HeaderText =Report>

< itemtemplate>

< asp:Button ID =Button5runat =serverText =获取详细信息BackColor =#33CCFFCssClass =getdetailsOnClick = Button5_Click/>









< footerstyle backcolor =白色forecolor =#000066>

< HeaderStyle BackColor =#006699Font-Bold =TrueForeColor =White/>

< pagerstyle backcolor =Whiteforecolor =#000066horizo​​ntalalign =Left>

< rowstyle forecolor =#000066>

< SelectedRowStyle BackColor =#669999Font-Bold =TrueForeColor =White/>

< sortedascendingcellstyle backcolor =#F1F1F1>

< sortedascendingheaderstyle backcolor =#007DBB>

< sorteddescendingcellstyle backcolor =# CAC9C9>

< sorteddescendingheaderstyle backcolor =#00547E>









C#代码



protected void pdf_Click1(object sender,ImageClickEventArgs e)

{

使用(StringWriter sw = new StringWriter())

{

using(HtmlTextWriter hw = new HtmlTextWriter(sw))

{





GridView1.Columns [0] .Visible = false; //隐藏包含CheckBox的列

foreach(GridView1.Rows中的GridViewRow行)

{

if(row.RowType == DataControlRowType。 DataRow)

{



row.Visible =(row.FindControl(chkchild)作为CheckBox)。检查; //如果未选中CheckBox则隐藏行

}

}



GridView1.RenderControl(hw) ;

StringReader sr = new StringReader(sw.ToString());

文件pdfDoc =新文件(PageSize.A4,10f,10f,10f,0f);

HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

PdfWriter.GetInstance(pdfDoc,Response.OutputStream);

pdfDoc.Open();

htmlparser.Parse(sr);

pdfDoc.Close();



Response.ContentType =application / pdf;

Response.AddHeader(content-disposition,attachment; filename = GridViewExport.pdf);

Response.Cache.SetCacheability(HttpCacheability.NoCache );

Response.Write(pdfDoc);

Response.End( );

}

}

}

Could not find a part of the path of the image


Asp.net

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="624px" CssClass="grid" OnRowCommand="OnRowCommand"
AllowPaging="True" AllowSorting="True" BackColor="White" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" PageSize = "5"
OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting" DataKeyNames="id" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">

<columns> <asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" runat="server" onclick="CheckAll(this)"/>
</HeaderTemplate>
<itemtemplate>
<asp:CheckBox ID="chkchild" runat="server" />


<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="updatedby" HeaderText="updatedby" SortExpression="updatedby" />
<asp:BoundField DataField="username" HeaderText="username" SortExpression="username" />
<asp:BoundField DataField="password" HeaderText="password" SortExpression="password" />
<asp:BoundField DataField="mail" HeaderText="mail" SortExpression="mail" />

<asp:BoundField DataField="imagename" HeaderText="imagename" SortExpression="imagename" />
<%--<asp:CommandField ShowEditButton="true" ButtonType="image" EditImageUrl="~/images/delete.jpg" HeaderText="Delete" />--%>

<asp:ImageField DataImageUrlField="uploadimage" HeaderText="uploadimage" ControlStyle-Width = "60" ControlStyle-Height = "100">



<asp:CommandField ShowEditButton="True" />

<asp:TemplateField HeaderText="Delete" >
<itemtemplate>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/delete.jpg"
OnClientClick="return confirm('Are you sure you want to delete?')" Text="Delete" CommandName="Delete" />


<asp:TemplateField HeaderText="Update">
<itemtemplate>
<asp:LinkButton ID="link" runat="server" Text="Choose" CssClass="linkbutton" CommandName="Choose">


<asp:TemplateField HeaderText="Print">
<itemtemplate>

<asp:ImageButton ID="excel" runat="server" ImageUrl="images/excel-icon.png" OnClick="excel_Click" /> <asp:ImageButton ID="pdf" runat="server" ImageUrl="images/PDF-icon.png" OnClick="pdf_Click1"/> <asp:ImageButton ID="word" runat="server" ImageUrl="images/MS-Office-2003-Word-icon.png" OnClick="word_Click"/>




<asp:TemplateField HeaderText="Report">
<itemtemplate>
<asp:Button ID="Button5" runat="server" Text="Get details" BackColor="#33CCFF" CssClass="getdetails" OnClick="Button5_Click"/>




<footerstyle backcolor="White" forecolor="#000066">
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<pagerstyle backcolor="White" forecolor="#000066" horizontalalign="Left">
<rowstyle forecolor="#000066">
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<sortedascendingcellstyle backcolor="#F1F1F1">
<sortedascendingheaderstyle backcolor="#007DBB">
<sorteddescendingcellstyle backcolor="#CAC9C9">
<sorteddescendingheaderstyle backcolor="#00547E">




C# code

protected void pdf_Click1(object sender, ImageClickEventArgs e)
{
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{


GridView1.Columns[0].Visible = false; //Hide the Column containing CheckBox
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{

row.Visible = (row.FindControl("chkchild") as CheckBox).Checked; //Hide the Row if CheckBox is not checked
}
}

GridView1.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
}
}
}

推荐答案

检查以下链接



export-gridview -to-pdf / [ ^ ]



希望对您有所帮助。
Check the following link

export-gridview-to-pdf/[^]

Hope it help you.


这篇关于在ASP.Net中将所选(已选中)GridView Rows导出为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆