Click here to Skip to main content
15,893,368 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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();
}
}
}
Posted
Updated 13-Nov-14 23:06pm
Comments
Afzaal Ahmad Zeeshan 14-Nov-14 5:12am    
Please format your question.
Member 10918596 14-Nov-14 5:28am    
sry i want selected checkbox row to PDF in ASP.Net bt here it shows image file only could not found
Afzaal Ahmad Zeeshan 14-Nov-14 5:38am    
You have still not formatted the question.

1 solution

Check the following link

export-gridview-to-pdf/[^]

Hope it help you.
 
Share this answer
 
Comments
IpsitaMishra 14-Nov-14 7:49am    
I think you are referring to the same link.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900