Saturday, January 8, 2011

Convert datagrid into text file in asp.net

You can use this code to save datagrid into text file:



code snippet:


     StreamWriter sw = new StreamWriter("hello.txt");

        foreach(DataGridItem dg in   datagrid1.Items)

        {

             string str = string.Empty;

             for (int i = 0; i < dg.Cells.Count; i++)

            {

                str += dg.Cells[i].Text " ";

             }

             sw.WriteLine(str);          

        }

         sw.Close();

No comments:

Post a Comment