在ASP.Net中将选定(已选中)GridView Rows导出为PDF 无法找到图像路径的一部分如何解决此错误ti一次又一次显示错误但它没有图像如何将选定的gridview deatails转换为pdf?得到错误?下面的代码显示了此错误
<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" />
</ItemTemplate>
</asp:TemplateField>
<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:ImageField DataImageUrlField="uploadimage" HeaderText="uploadimage" ControlStyle-Width = "60" ControlStyle-Height = "100">
</asp:ImageField>
<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" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Update">
<ItemTemplate>
<asp:LinkButton ID="link" runat="server" Text="Choose" CssClass="linkbutton" CommandName="Choose"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Print">
<ItemTemplate>
<table>
<tr>
<td><asp:ImageButton ID="excel" runat="server" ImageUrl="images/excel-icon.png" OnClick="excel_Click" /></td>
<td> <asp:ImageButton ID="pdf" runat="server" ImageUrl="images/PDF-icon.png" OnClick="pdf_Click1"/></td>
<td><asp:ImageButton ID="word" runat="server" ImageUrl="images/MS-Office-2003-Word-icon.png" OnClick="word_Click"/></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Report">
<ItemTemplate>
<asp:Button ID="Button5" runat="server" Text="Get details" BackColor="#33CCFF" CssClass="getdetails" OnClick="Button5_Click"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
C#代码
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
GridView1.Columns[0].Visible = false;
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{`
row.Visible = (row.FindControl("chkchild") as CheckBox).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();
}
}
答案 0 :(得分:0)
你忘记了波尔多&#34;〜&#34;在ImageUrls中,检查并更改ImageButtons中的代码
<asp:ImageButton ID="excel" runat="server" ImageUrl="~/images/excel-icon.png" OnClick="excel_Click" />