DetailsView数据更新

protected void dvArea_ModeChanging(object sender, DetailsViewModeEventArgs e) { //判断模式 if (e.NewMode == DetailsViewMode.Edit) { dvArea.ChangeMode(DetailsViewMode.Edit); Bind(); } else if (e.CancelingEdit) { //取消编辑 if (dvArea.CurrentMode == DetailsViewMode.Edit) { dvArea.ChangeMode(DetailsViewMode.ReadOnly); Bind(); } } } protected void ddlArea_DataBinding(object sender, EventArgs e) { string strAreaid = ((HiddenField)this.dvArea.FindControl("hfAreaid")).Value; DropDownList ddl = (DropDownList)this.dvArea.FindControl("ddlArea"); DataTable table = country.getAreaList(0); if (table.Rows.Count > 0) { ddl.Items.Insert(0, new ListItem("请选择代理地区", "")); foreach (DataRow dw in table.Rows) { int parentid = Convert.ToInt32(dw["areaid"].ToString()); DataTable subTable = country.getAreaList(parentid); string strSubArea = ""; if (subTable.Rows.Count > 0) { ListItem li = new ListItem(dw["cname"].ToString() + " - " + dw["areaname"].ToString(), dw["areaid"].ToString()); ddl.Items.Add(li); isSelected(dw["areaid"].ToString(), strAreaid, li); foreach (DataRow dw1 in subTable.Rows) { strSubArea = dw["cname"].ToString() + " - " + dw["areaname"].ToString() + " - " + dw1["areaname"].ToString(); li = new ListItem(strSubArea, dw1["areaid"].ToString()); ddl.Items.Add(li); isSelected(dw1["areaid"].ToString(), strAreaid, li); } } else { ListItem li = new ListItem(dw["cname"].ToString() + " - " + dw["areaname"].ToString(), dw["areaid"].ToString()); ddl.Items.Add(li); isSelected(dw["areaid"].ToString(), strAreaid, li); } } } } protected void dvArea_ItemCommand(object sender, DetailsViewCommandEventArgs e) { if (e.CommandName == "Update") { //检查email string strNewEmail = ((TextBox)dvArea.Rows[1].Cells[1].Controls[0]).Text; string stryonghuid = this.dvArea.DataKey["yonghuid"].ToString(); DataTable table = user.IsExtie(strNewEmail); if (table.Rows.Count > 0) { if (table.Rows[0][0].ToString() != stryonghuid) this.Page.ClientScript.RegisterStartupScript(typeof(Page), "alert", ""); else { //更新数据 int yonghuid = Convert.ToInt32(stryonghuid); string username = strNewEmail; string email = strNewEmail; int storeid = Convert.ToInt32(this.dvArea.DataKey["storeid"].ToString()); string storename = ((TextBox)dvArea.Rows[2].Cells[1].Controls[0]).Text; int areanum = Convert.ToInt32(((DropDownList)dvArea.Rows[3].Cells[1].FindControl("ddlArea")).SelectedValue); string storemanager = ((TextBox)dvArea.Rows[4].Cells[1].Controls[0]).Text; string contact = ((TextBox)dvArea.Rows[5].Cells[1].Controls[0]).Text; string telephone = ((TextBox)dvArea.Rows[6].Cells[1].Controls[0]).Text; string fax = ((TextBox)dvArea.Rows[7].Cells[1].Controls[0]).Text; string address = ((TextBox)dvArea.Rows[8].Cells[1].Controls[0]).Text; string zipcode = ((TextBox)dvArea.Rows[9].Cells[1].Controls[0]).Text; string introduction = ((TextBox)dvArea.Rows[12].Cells[1].FindControl("tbInfo")).Text; if(store.updateStore(yonghuid,username,email,storeid,contact,storemanager,storename,areanum,telephone,fax,address,zipcode,introduction)>0) this.Page.ClientScript.RegisterStartupScript(typeof(Page), "alert", ""); else this.Page.ClientScript.RegisterStartupScript(typeof(Page), "alert", ""); } } } } protected void dvArea_ItemUpdating(object sender, DetailsViewUpdateEventArgs e) { for (int i = 0; i < e.NewValues.Count; i++) { if (e.NewValues[i] != null) { e.NewValues[i] = Server.HtmlEncode(e.NewValues[i].ToString()); } } } protected void dvArea_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e) { Bind(); }

 

你可能感兴趣的:(C#编程)