Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 898
  • Last Modified:

C# write to text file from gridview error

Hi - Im trying to write to a text file froma  gridview using the follwing code but get the error message at the bottom --

protected void Button2_Click(object sender, EventArgs e)
    {
        String strDestinationFile;
        strDestinationFile = "C:\\output.txt";
        TextWriter tw = new StreamWriter(strDestinationFile);

        //writing the header
        for (int x = 0; x < GridView1.Columns.Count; x++)
        {
            tw.Write(GridView1.Columns[x].HeaderText);
            if (x != GridView1.Columns.Count - 1)
            {
                tw.Write(", ");
            }

        }
        tw.WriteLine();

        //writing the data
        for (int x = 0; x < GridView1.Rows.Count - 1; x++)
        {
            for (int y = 0; y < GridView1.Columns.Count; y++)
            {
                tw.Write(GridView1.Rows[x].Cells.Value);
                if (y != GridView1.Columns.Count - 1)
                {
                    tw.Write(", ");
                }
            }
            tw.WriteLine();
        }
        tw.Close();



    }

ERROR MESSAGE
CS1061: 'System.Web.UI.WebControls.TableCellCollection' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'System.Web.UI.WebControls.TableCellCollection' could be found (are you missing a using directive or an assembly reference?)
0
owenja
Asked:
owenja
1 Solution
 
informaniacCommented:
Should be Text instead of Value

GridView1.Rows[x].Cells[y].Text;
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now