Dear all,
Please tell me
how to export gridview to txt file in asp.net.
this is my code but not working
public void MakeTextFileFromGridView ( )
{
StringBuilder sb = new StringBuilder ( );
for ( int i = 0; i <= grdForm4A.Rows.Count-1; i++ )
{
for ( int j = 0; j <= grdForm4A.Columns.Count-1; j++ )
{
sb.Append ( grdForm4A.Rows[i].Cells[j].ToString ( ) );
}
sb.Append ( "<br/>" );
}
Response.Clear ( );
Response.AddHeader ( "content-disposition",
"attachment;filename=FileName.txt" );
Response.Charset = "";
Response.Cache.SetCacheability ( HttpCacheability.NoCache );
Response.ContentType = "application/vnd.text";
System.IO.StringWriter stringWrite = new System.IO.StringWriter ( );
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter ( stringWrite );
Response.Write ( sb.ToString ( ) );
Response.End ( );
}
Thanks in adv.