2011-12-17 77 views
0

我想在ASP.net中編寫,更新或編輯XML gridview的函數(在Visual Studio 2010中),但我不知道應該使用哪個操作?編輯ASP.NET中的XML Gridview的函數

這是我的代碼,但它不起作用。當我點擊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(); 
    } 

感謝

回答

1

我可能會得到這個錯誤的,但你想通過加載到一個GridView修改web.config文件?我不認爲你可以用web.config做這樣的事情 - 所以它可能會被認爲是拋出erorrs。

在運行時修改web.config是否考慮使用WebConfigurationManager。這個對象是建立在這一點上的。儘管前面的鏈接說ASP.Net 2.0和3.5,但在4.0(Visual Studio 2010)中可以。這SO Question給出了一個非常明確的代碼示例。