0

I want to write, update or edit a function for an XML gridview in ASP.net (in visual studio 2010), but I don't know which action I should use?

This is my code but it doesn't work. When I click edit on the gridview an exception occured:

 private DataSet ds;
    DataRow r;
    protected void Page_Load(object sender, EventArgs e)
    {
        ds = new DataSet();
        ds.ReadXml(Server.MapPath("../web.config"));
        GridView1.DataSource = ds.Tables["user"];
        GridView1.DataBind();

    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GridView1.EditIndex = e.RowIndex;
        GridView1.DataBind();
    }

    protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {

        r = ds.Tables["user"].Rows[e.AffectedRows];
        r["password"] = FormsAuthentication.HashPasswordForStoringInConfigFile(GridView1.SelectedRow.Cells[1].ToString(), "MD5");


        ds.AcceptChanges();
        ds.WriteXml(Server.MapPath("web.config"));
        GridView1.DataBind();
    }

thanks

Crab Bucket
  • 6,219
  • 8
  • 38
  • 73
Ava Bahari
  • 59
  • 1
  • 3
  • 9

1 Answers1

1

I may have got this wrong but are you trying to amend the web.config file by loading into a gridview? I don't think you can do things like that with web.config - so it's probably to be expected that it's throwing erorrs.

For amending the web.config at runtime have you considered using WebConfigurationManager. The object is built with this in mind. Although the previous link says ASP.Net 2.0 and 3.5 it would be fine in 4.0 (Visual Studio 2010). This SO Question gives a very clear code sample.

Community
  • 1
  • 1
Crab Bucket
  • 6,219
  • 8
  • 38
  • 73