Rini

Rini

  • 1.5k
  • 204
  • 31.6k

export to xcel

Mar 31 2014 1:02 AM
Dear sir,
in my program,i have a button download..
when i click the buttondownload i want to downloadthe details and also want the count of the details.
when i click the download button..
download is done.but didn't display the count
my code is
 if (DropDownList1.SelectedIndex == 1)
            {
                if (TextBox1.Text != string.Empty)
                {
                    dec2DivId = TextBox1.Text;
                    //  gridPinSearch();
                    MobileSp spmobile = new MobileSp();
                    DataTable dtblc = new DataTable();
                    dtblc = spmobile.pinCodeSearch(dec2DivId);
                    Response.Clear();
                    Response.Buffer = true;
                    Response.AddHeader("content-disposition", "attachment;filename=PinnumberSearch.csv");
                    Response.Charset = "";
                    Response.ContentType = "application/text";
                    StringBuilder sb = new StringBuilder();
                    for (int k = 0; k < dtblc.Columns.Count; k++)
                    {
                        sb.Append(dtblc.Columns[k].ColumnName + ',');
                    }
                    //append new line
                    sb.Append("\r\n");
                    txtCount.Text = dtblc.Rows.Count.ToString();
                    for (int i = 0; i < dtblc.Rows.Count; i++)
                    {
                        for (int k = 0; k < dtblc.Columns.Count; k++)
                        {
                         sb.Append(dtblc.Rows[i][k].ToString().Replace(",", ";") + ',');
                        }
                        //append new line
                        sb.Append("\r\n");
                    }
                    Response.Output.Write(sb.ToString());
                    Response.Flush();
                    Response.End();                
                }
            }         

Answers (3)