Click here to Skip to main content
15,908,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public void gridviewfill()
{
ds = ObjOrdersBll.Invoice_Status_Report(ObjOrdersBo);

if (ds.Tables[0].Rows.Count > 0)
{
   if (txtInvoiceNo.Text == "")
   {
       for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
       {
           //ds.Tables[0].Rows[i]["DeliveryDate"] = Convert.ToDateTime(ds.Tables[0].Rows[i].ItemArray[1]).ToString("yyyyMMdd");
           //ds.Tables[0].Rows[i]["DeliveryTime"] = ds.Tables[0].Rows[i].ItemArray[2].ToString();//.Replace(':',' ').ToString();
           ds.Tables[0].Rows[i]["FromDate"] = DateText(ds.Tables[0].Rows[i].ItemArray[4].ToString());
           ds.Tables[0].Rows[i]["Todate"] = DateText(ds.Tables[0].Rows[i].ItemArray[5].ToString());
       }
   }

   dtExport = ds.Tables[0];


   gdvInvoices.DataSource = ds.Tables[0];
   gdvInvoices.DataBind();
   gdvInvoices.Enabled = true;
   gdvInvoices.Visible = true;

   //DataTableToTextFile(dtExport, Server.MapPath("TempImages\\Invoice_Report.txt"));
   BindText(Server.MapPath("TempImages\\Invoice_Report.txt"));

   Clear();
}


C#
public void BindText(string filePath)
{
    try
    {
        string attachFileName = "Invoice" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";  
        System.IO.FileInfo file = new System.IO.FileInfo(filePath);
        Response.ClearContent();
        Response.AddHeader("content-disposition", "attachment; filename=" + attachFileName);
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < gdvInvoices.Columns.Count; i++)
        {
            str.Append(gdvInvoices.Columns[i].HeaderText + ',');
        }
        str.Append("\n");
        for (int j = 0; j < gdvInvoices.Rows.Count; j++)
        {
            for (int k = 0; k < gdvInvoices.Columns.Count; k++)
            {
                str.Append(gdvInvoices.Rows[j].Cells[k].Text + ',');
            }
            str.Append("\n");
        }
        Response.Write(str.ToString());
       
        Response.End();

        System.Threading.Thread.Sleep(3000);
        Clear();
    }
    catch (Exception ex) { }
}

This is how i was trying to display Text file After Binding of Gridview

Problem is TextFile is Showing But Gridview is not Displaying on the Page

Can anyone Suggest me to get out of this problem ?

Thanks Advance.
Posted
v3
Comments
Please comment these line once and try.

//Response.Write(str.ToString());
//Response.End();
Mart Rijkers 11-Oct-13 9:31am    
What does the "Clear();" command do?
Mart Rijkers 11-Oct-13 9:33am    
I also do not understand why you let your application sleep for 3 seconds during what I believe is a postback action of your webpage?
idenizeni 11-Oct-13 18:54pm    
You're clearing the response with this line...
Response.ClearContent();
So anything that was in the response (e.g. the GridView) has been removed by this line. The text shows because you 'fill' the response with it after you clear the response content.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900