المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Problem wirh Response.End() while exporting Datatable results to Excel file.



C# Programming
07-08-2011, 02:01 AM
Hi,
I have a datatable from which i am exporting the results to Excel file.The exporting happens perfectly....But web page is not getting loaded completely.Its because of the Response.End();.It terminates the execution of the page further.
Because I have some other code after Response.End(); to get executed and needs to be displayed in the page.Is there a way to get the complete execution of the page.I am struck with this problem for while now..........Any help is appreciated.

DataTable dtMemberList = LinqToDatatable.LinqToDataTable(MembersList);
string attachment = "attachment; filename=Search.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
Response.Write("\n");
Response.Write("Search Results");
Response.Write("\n");
string tab = "";

Response.Write(tab + "Member ID");
tab = "\t";
Response.Write(tab + "Memberdoc Received Date");
tab = "\t";
Response.Write(tab + "Memberdoc Import Date");
tab = "\t";
Response.Write(tab + "Memberdoc Status");
tab = "\t";
Response.Write(tab + "Memberdoc Type");
Response.Write("\n");
int i;
foreach (DataRow dr in dtMemberList.Rows)
{
tab = "";
for (i = 0; i < dtMemberList.Columns.Count; i++)
{
Response.Write(tab + dr[i].ToString());
tab = "\t";
}
Response.Write("\n");
}
Response.End();