473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Postback, XML/XSLT, Gridview, Response object question


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(e xcelXsltFileName),
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.

Jun 9 '07 #1
0 1609

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag,...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
2
by: Rob Roberts | last post by:
Is there any way to prevent a ButtonField in a GridView from doing a postback when clicked? I want to use my own onclick handler to call window.open('SomePage.aspx') to display a page in a new...
0
by: steve.craver | last post by:
I am working with a multi-field search form which, when the form is submitted, queries a database and returns the results into a paginated GridView object. The site is being developed with master...
0
by: Managed Code | last post by:
Hello All, Here is my issue and thanks in advance for any assistance. I have a base page with a dropdownlist that fires an event with the selected index. The content page catches the event and...
0
by: John Smith | last post by:
If anyone can help, I would very muchly appreciate it. I have a main page that uses the .net 2.0 menu control with the multiview controls as the menu choices. This works fine. One of the menu...
2
by: cartmann | last post by:
Hi, I have a gridview with a template column. In the template column i have two commandbuttons. When clicking the buttons I enter the cmd_click event - but how do I read in which row the button...
7
by: Tony Girgenti | last post by:
Hello. I'm trying to undetrstand ASP.NET 2.0 and javascript. When i have a button and i click on it and i see the web broswer progress bar at the bottom do something, does that mean that there...
1
by: gabe | last post by:
How do you call a client side javascript callback method after an update panel has posted back to the server? I have two update panels (A + B) with a gridview in each panel. GridView B has a...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.