R
ronc85
My environment is ASP.NET 2.0, C# and AJAX.
I'm having a problem with 'Button Click' logic which is trying to
display a Gridview and
then use XML/XSLT to build an Excel file. The following code does not
display the Gridview but opens the created file in Excel.If I comment
out the ExportDatasetToExcel routine the Gridview displays correctly.
I'm assuming the problem is something to do with the Response
methods.
protected void Button1_Click(object sender, EventArgs e)
{
ProductLocation objProductLocation = new ProductLocation ();
DataSet ds;
ds = objProductLocation.GetProductLocationList();
GridView1.DataSource = ds;
GridView1.DataBind();
string excelXsltFileName = "ProductLocationList.xsl";
string excelOutputFileName = "ProductLocationList.xls";
Hashtable excelXsltArguments = null;
ExcelUtility.ExportDatasetToExcel(Server.MapPath(excelXsltFileName),
excelOutputFileName,
ds,
Response,
excelXsltArguments
);
}
public static bool ExportDatasetToExcel(string XSLTFileNameWithPath,
string excelOutputFileName, DataSet ds, System.Web.HttpResponse
Response, System.Collections.Hashtable excelXsltArguments)
{
if (ds == null && ds.Tables[0].Rows.Count < 1)
return false;
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition",
"attachment;filename=" + excelOutputFileName);
XslTransform xslt = new XslTransform();
xslt.Load(XSLTFileNameWithPath);
XsltArgumentList xsltArguments = new XsltArgumentList();
if (excelXsltArguments != null) // Check for parameters to be
passed to XSLT
{
foreach (System.Collections.DictionaryEntry de in
excelXsltArguments)
xsltArguments.AddParam(de.Key.ToString(), "",
de.Value);
}
XmlDocument xml = new XmlDocument();
xml.LoadXml(ds.GetXml());
xslt.Transform(xml.CreateNavigator(), xsltArguments,
Response.Output);
Response.Flush();
Response.Close();
return true;
}
Sal P.
I'm having a problem with 'Button Click' logic which is trying to
display a Gridview and
then use XML/XSLT to build an Excel file. The following code does not
display the Gridview but opens the created file in Excel.If I comment
out the ExportDatasetToExcel routine the Gridview displays correctly.
I'm assuming the problem is something to do with the Response
methods.
protected void Button1_Click(object sender, EventArgs e)
{
ProductLocation objProductLocation = new ProductLocation ();
DataSet ds;
ds = objProductLocation.GetProductLocationList();
GridView1.DataSource = ds;
GridView1.DataBind();
string excelXsltFileName = "ProductLocationList.xsl";
string excelOutputFileName = "ProductLocationList.xls";
Hashtable excelXsltArguments = null;
ExcelUtility.ExportDatasetToExcel(Server.MapPath(excelXsltFileName),
excelOutputFileName,
ds,
Response,
excelXsltArguments
);
}
public static bool ExportDatasetToExcel(string XSLTFileNameWithPath,
string excelOutputFileName, DataSet ds, System.Web.HttpResponse
Response, System.Collections.Hashtable excelXsltArguments)
{
if (ds == null && ds.Tables[0].Rows.Count < 1)
return false;
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition",
"attachment;filename=" + excelOutputFileName);
XslTransform xslt = new XslTransform();
xslt.Load(XSLTFileNameWithPath);
XsltArgumentList xsltArguments = new XsltArgumentList();
if (excelXsltArguments != null) // Check for parameters to be
passed to XSLT
{
foreach (System.Collections.DictionaryEntry de in
excelXsltArguments)
xsltArguments.AddParam(de.Key.ToString(), "",
de.Value);
}
XmlDocument xml = new XmlDocument();
xml.LoadXml(ds.GetXml());
xslt.Transform(xml.CreateNavigator(), xsltArguments,
Response.Output);
Response.Flush();
Response.Close();
return true;
}
Sal P.