protected void GV_RowDeleting(object sender, GridViewDeleteEventArgs e) { string lbid = GV.DataKeys[e.RowIndex].Value.ToString(); List <DXLb> lbs = SQLHelper.GetEntities <DXLb>(" IsDeleted=0 AND id=" + lbid); if (lbs.Count > 0) { DXLb lb = lbs[0]; SQLHelper.DeleteEntity <DXLb>(lb); if (lb.ParentId == 0) { bindDdlLbid(); } } bindGv(); alert.Show(Page, "删除成功"); return; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["pid"] != null) { pid = Request.QueryString["pid"].ToString(); List <DXLb> lbs = SQLHelper.GetEntities <DXLb>(""); if (lbs.Count > 0) { DXLb lb = lbs[0]; pidLink.NavigateUrl = "LbManage.aspx?pid=" + pid; pidLink.Text = lb.LbName; } } else { pidLink.NavigateUrl = "LbManage.aspx"; pidLink.Text = "顶级类"; } hpid.Value = pid; RebindGridView(false); } }
protected void GV_RowCommand(object sender, GridViewCommandEventArgs e) { System.Web.UI.WebControls.Button btn = e.CommandSource as System.Web.UI.WebControls.Button; if (btn == null) { return; } int index = ((System.Web.UI.WebControls.GridViewRow)btn.Parent.Parent).RowIndex; DataKey key = this.GV.DataKeys[index]; string lbid = key.Value.ToString(); GridViewRow gvr = GV.Rows[index]; if (e.CommandName == "Save") { //查找 title控件 TextBox txtTitle = null; try { txtTitle = this.GV.Rows[index].Cells[2].Controls[0] as TextBox; } catch { alert.Show(Page, "未找到类别名称文本框控件"); return; } string title = pg.GetSafeString(txtTitle.Text.Trim()); if (title == "") { alert.ShowAndBack(Page, "请填写类别名称"); return; } SQLHelper_ db = new SQLHelper_(); if (lbid.Length > 0) { //更新 List <DXLb> lbs = SQLHelper.GetEntities <DXLb>(" Id=" + lbid); DXLb lb = lbs[0]; lb.LbName = title; if (!SQLHelper.UpdateEntity <DXLb>(lb)) { alert.Show(Page, "编辑保存失败"); } else { GV.EditIndex = -1; bindGv(); } } else { try { DXLb lb = new DXLb { LbName = title, ParentId = Int32.Parse(ddlLbid.SelectedValue), IsDeleted = false }; SQLHelper.CreateEntity <DXLb>(lb); GV.EditIndex = -1; bindGv(); if (ddlLbid.SelectedValue == "0") { bindDdlLbid(); } } catch (Exception) { alert.Show(Page, "添加失败 "); //throw; } } } }