Click here to Skip to main content
15,905,323 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to export a grid view row in ti pdf . all text are export but image in grid view row are not exported some one help me urgent please
Posted

1 solution

 
Share this answer
 
Comments
Member 8632652 14-Mar-13 0:31am    
Cs code is

protected void LinkButton1_Click(object sender, EventArgs e)
{
int rindex = (((GridViewRow)(((LinkButton)(sender)).Parent.BindingContainer))).RowIndex;
string IId = GridView1.DataKeys[rindex]["Id"].ToString();
Download1(IId);
string strFileName = "test.pdf";
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + strFileName + "");
Response.Cache.SetCacheability(HttpCacheability.NoCache);

StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.RenderControl(hw);
string s = sw.ToString().Replace("%20", " ");
s = Regex.Replace (s, "\r\n", string.Empty);
s = Regex.Replace(s, "\t", string.Empty);
s = Regex.Replace(s, " ", string.Empty);
s = Regex.Replace(s, HTML_TAG_PATTERN, string.Empty);
StringReader sr = new StringReader(s);
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.Write(pdfDoc);
Response.End();
}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string id = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
DataTable dt = con.GetData("select * from Download where Id='" + id + "'");
if (dt.Rows.Count > 0)
{
System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)e.Row.FindControl("Image1");
string url = "Download/" + dt.Rows[0]["Photo1"].ToString();
img.ImageUrl = GetUrl(url);
}
}


}
public void Download1(string id)
{
string i = id;
DataTable dt = con.GetData("select * from Download where Id='" + i + "'");
if (dt != null)
{
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.AllowPaging = false;
return;
}
}
protected string GetUrl(string imagepath)
{

string[] splits = Request.Url.AbsoluteUri.Split('/');

if (splits.Length >= 2)
{

string url = splits[0] + "//";

for (int i = 2; i < splits.Length - 1; i++)
{

url += splits[i];

url += "/";

}

return url + imagepath;

}

return imagepath;

}
This code expport text properly but never image
what i do
plz help

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