62,046
社区成员
发帖
与我相关
我的任务
分享
//页面加载
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
DateBind();
if (this.gridview1.SelectedIndex > -1)
// Call UpdateRow on every postback
this.GVLocalization.UpdateRow(this.GVLocalization.SelectedIndex, false);
}
//gridview绑定
private void DateBind()
{
string filepath = HttpContext.Current.Server.MapPath("/XXX.xml");
DataSet ds = new DataSet();
ds.ReadXml(filepath);
this.gridview1.DataSource = ds.Tables[0];
this.gridview1.DataBind();
}
protected void gridview1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//更新选中行的记录到XML文件
string name = ((TextBox)GVLocalization.Rows[e.RowIndex].Cells[0].Controls[0]).Text.ToString();
string value = ((TextBox)GVLocalization.Rows[e.RowIndex].Cells[1].Controls[0]).Text.ToString();
bool enable = ((CheckBox)GVLocalization.Rows[e.RowIndex].Cells[2].Controls[0]).Checked;
GridViewRow row = gridview1.Rows[e.RowIndex];
string filepath = HttpContext.Current.Server.MapPath(@"/XXX.xml");
DataSet ds = new DataSet();
ds.ReadXml(filepath);
DataRow dr = ds.Tables[0].Rows[row.DataItemIndex];
dr["name"] = name;
dr["value"] = value;
dr["enable"] = enable;
ds.WriteXml(filepath);
GVLocalization.EditIndex = -1;
DataBind();//此方法为什么不执行?
DataBind();
GVLocalization.EditIndex = -1;
DataBind();//此方法为什么不执行?