protected void btnSave_Click(object sender, EventArgs e) { try { int Id = Int32.Parse(CatID.Value); LPS.CarCategory cat = new LPS.CarCategory(); cat = db.CarCategories.FirstOrDefault(x => x.CatID == Id); cat.CatParentID = Convert.ToInt32(ddlParentCat.SelectedValue); cat.CatName = txtPCName.Value.Trim(); if (cat.CatParentID == 0) { cat.CatLevel = 0; } else { cat.CatLevel = 1; } db.SaveChanges(); LoadData(); } catch (Exception ex) { } }
protected void gvListItem_RowCommand(object sender, GridViewCommandEventArgs e) { int id = Int32.Parse(e.CommandArgument.ToString()); GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer); Label lblTitle = (Label)row.Cells[1].FindControl("lblName"); if (e.CommandName.ToLower() == "deleteitem") { LPS.CarCategory obj = db.CarCategories.Find(id); db.CarCategories.Remove(obj); db.SaveChanges(); LoadData(); } }
private void LoadData() { if (!comClass.IsNumeric(Request.QueryString.Get("Id"))) { Response.Redirect(BackUrl.Value); } else { try { int Id = Int32.Parse(Request.QueryString.Get("Id")); dataList = db.CarCategories.Where(x => x.CatLevel == 0 && x.CatID != Id).OrderBy(x => x.CatName).ToList(); ddlDataList.Add(new LPS.CarCategory() { CatID = 0, CatLevel = 0, CatName = "Root" }); ddlDataList.AddRange(dataList); ddlParentCat.DataSource = ddlDataList; ddlParentCat.DataTextField = "CatName"; ddlParentCat.DataValueField = "CatId"; ddlParentCat.DataBind(); LPS.CarCategory cat = new LPS.CarCategory(); cat = db.CarCategories.FirstOrDefault(x => x.CatID == Id); CatID.Value = cat.CatID.ToString(); txtPCName.Value = cat.CatName; ddlParentCat.SelectedValue = cat.CatParentID.ToString(); lblCatName.Text = cat.CatName; } catch (Exception ex) { Response.Redirect(BackUrl.Value); } } }
protected void btnSave_Click(object sender, EventArgs e) { try { LPS.CarCategory cat = new LPS.CarCategory(); cat.CatParentID = Convert.ToInt32(ddlParentCat.SelectedValue); cat.CatName = txtPCName.Value.Trim(); if (cat.CatParentID == 0) { cat.CatLevel = 0; } else { cat.CatLevel = 1; } db.CarCategories.Add(cat); db.SaveChanges(); LoadData(); } catch (Exception ex) { } }
private void LoadData() { if (!comClass.IsNumeric(Request.QueryString.Get("Id"))) { Response.Redirect(BackUrl.Value); } else { try { int Id = Int32.Parse(Request.QueryString.Get("Id")); dataList = db.CarCategories.Where(x => x.CatLevel == 0 && x.CatID!=Id).OrderBy(x => x.CatName).ToList(); ddlDataList.Add(new LPS.CarCategory() { CatID = 0, CatLevel = 0, CatName = "Root" }); ddlDataList.AddRange(dataList); ddlParentCat.DataSource = ddlDataList; ddlParentCat.DataTextField = "CatName"; ddlParentCat.DataValueField = "CatId"; ddlParentCat.DataBind(); LPS.CarCategory cat = new LPS.CarCategory(); cat = db.CarCategories.FirstOrDefault(x => x.CatID == Id); CatID.Value = cat.CatID.ToString(); txtPCName.Value = cat.CatName; ddlParentCat.SelectedValue = cat.CatParentID.ToString(); lblCatName.Text = cat.CatName; } catch (Exception ex) { Response.Redirect(BackUrl.Value); } } }