【问题标题】:Editing function for an XML Gridview in ASP.NETASP.NET 中 XML Gridview 的编辑功能
【发布时间】:2011-12-17 13:57:51
【问题描述】:

我想在 ASP.net(在 Visual Studio 2010 中)中为 XML 网格视图编写、更新或编辑函数,但我不知道应该使用哪个操作?

这是我的代码,但它不起作用。当我在 gridview 上单击编辑时发生异常:

 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();
    }

谢谢

【问题讨论】:

    标签: asp.net xml visual-studio-2010


    【解决方案1】:

    我可能弄错了,但您是否尝试通过加载到 gridview 来修改 web.config 文件?我不认为你可以用 web.config 做这样的事情 - 所以它可能会引发错误。

    为了在运行时修改 web.config,您是否考虑过使用WebConfigurationManager。该对象是在考虑到这一点的情况下构建的。虽然前面的链接说 ASP.Net 2.0 和 3.5,但在 4.0(Visual Studio 2010)中会很好。这个SO Question 给出了一个非常清晰的代码示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-09
      • 1970-01-01
      • 2010-10-28
      • 2020-06-08
      • 1970-01-01
      相关资源
      最近更新 更多