Your dropdown is firing the event. Only thing is it is not going inside
word
block(
else...if
block). It may be because of string matching. May be you have given value in small case and checking in different case. In this kind of situations always use breakpoint and try stepping through the code.
Try this:
protected void ddl_chanched(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue.ToUpper == "PDF")
{
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
using (MemoryStream stream = new MemoryStream())
{
Chart1.SaveImage(stream, ChartImageFormat.Png);
iTextSharp.text.Image chartImage = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
string lbl1 = Label1.Text.ToString();
pdfDoc.Add(new Paragraph(lbl1));
chartImage.ScalePercent(75f);
pdfDoc.Add(chartImage);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Chart.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
}
}
else if (DropDownList1.SelectedValue.ToUpper() == "WORD")
{
Page.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
string tmpChartName = "test2.jpg";
string imgPath = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName;
Chart1.SaveImage(imgPath);
string imgPath2 = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName);
Response.Clear();
Response.ContentType = "application/vnd.ms-word";
Response.AddHeader("Content-Disposition", "attachment; filename=test.doc;");
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
string headerTable = @"<table><tr><td><img src="" + imgPath2 + @""></img></td></tr></table>";
Response.Write(headerTable);
Response.Write(stringWrite.ToString());
Response.End();
}
DropDownList1.AutoPostBack = true;
}
Hope it helps.
--Amit