Priya Bm

Priya Bm

  • NA
  • 33
  • 24.3k

export image from gridview to excel

Aug 25 2015 12:48 AM
 Hi,
 
I have a gridview with a image and my image or image path is not storing in db. Its common for all pages.
So how to export gridview with image to excel .
I searched i am getting solution that  images are stored in db.
 
Below is my aspx code.
<div class="box">
<asp:GridView ID="grdweekly" runat="server" CssClass="GridReport" OnRowDataBound="grdweekly_RowDataBound">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl="Images/Elephant.png" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#Eval("WeekNo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
 
CS Code for exporting:
protected void btnwexport_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=WeeklyECGReport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
using (StringWriter sw = new StringWriter())
{
HtmlTextWriter hw = new HtmlTextWriter(sw);
//To Export all pages
//grddaily.AllowPaging = false;
this.fillgrid();
grdweekly.HeaderRow.BackColor = Color.White;
foreach (TableCell cell in grdweekly.HeaderRow.Cells)
{
cell.Width = 140;
cell.Height = 190;
break;
}
grdweekly.RenderControl(hw);
//style to format numbers to string
string style = @"<style> .textmode { } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
}
 
Pls Help me.. Its very urgent. 
 
 

Answers (2)