I have gridview with 3 columns.
I generated 1 column with the help of RowDataBound event of Gridview, I want to export .txt file of that Gridview. The text file is also generated but in that Textfile following data is shown:
so how to export .txt in Gridview ?
LaxmikantPosted Nov 2, 2015, 11:45 PM
- Bindgrid();
- Response.Clear();
- Response.Buffer = true;
- Response.AddHeader("content-disposition", "attachment;filename=Vithal_Wadje.txt");
- Response.Charset = "";
- Response.ContentType = "application/text";
- GridView1.AllowPaging = false;
- GridView1.DataBind();
-
- StringBuilder Rowbind = new StringBuilder();
- for (int k = 0; k < GridView1.Columns.Count; k++)
- {
-
- Rowbind.Append(GridView1.Columns[k].HeaderText + ' ');
- }
-
- Rowbind.Append("\r\n");
- for (int i = 0; i < GridView1.Rows.Count; i++)
- {
- for (int k = 0; k < GridView1.Columns.Count; k++)
- {
-
- Rowbind.Append(GridView1.Rows[i].Cells[k].Text + ' ');
- }
-
- Rowbind.Append("\r\n");
- }
- Response.Output.Write(Rowbind.ToString());
- Response.Flush();
- Response.End();
-
or you can use the DataTable which is used for binding gridview and convert contents of DataTable to txt file.