//单击删除按钮 protected void BtnDelete_Click(object sender, EventArgs e) { PetCategory petcategory = new PetCategory(); for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBoxs"); if (cbox.Checked == true) { string sqlstr = GridView1.DataKeys[i].Value.ToString(); petcategory.DeletePetCategory(sqlstr); } } LoadData(); }
protected void BtnAdd_Click(object sender, EventArgs e) { string petcategoryID = tbPetCategoryID.Text.Trim().ToString(); string categoryName = tbCategoryName.Text.Trim().ToString(); string categoryInfo = tbCategoryInfo.Text.Trim().ToString(); CTPetCategory category = new CTPetCategory(); category.petCategoryID = petcategoryID; category.petCategoryName = categoryName; category.petCategoryInfo = categoryInfo; PetCategory petcategory = new PetCategory(); int insertStatus = 0; insertStatus = petcategory.InsertPetCategory(category); if (insertStatus != 0) { Response.Write("<script>alert('添加成功!')</script>"); } else { Response.Write("<script>alert('添加失败!')</script>"); } }
private void LoadPetCategory() { List<CTPetCategory> petcategoryList = new List<CTPetCategory>(); PetCategory petcategory = new PetCategory(); petcategoryList = petcategory.GetPetCategoryList(); ddlPetCategory.DataSource = petcategoryList; ddlPetCategory.DataTextField = "petCategoryName"; ddlPetCategory.DataValueField = "petCategoryID"; ddlPetCategory.DataBind(); ddlPetCategory.Items.Insert(0, new ListItem("", "")); ddlCategoryAdd.DataSource = petcategoryList; ddlCategoryAdd.DataTextField = "petCategoryName"; ddlCategoryAdd.DataValueField = "petCategoryID"; ddlCategoryAdd.DataBind(); }
//单击save按钮 protected void btnSave_Click(object sender, EventArgs e) { string petCategoryID = tbEditPetCategoryID.Text.Trim().ToString(); string petCategoryInfo = tbEditPetCategoryInfo.Text.Trim().ToString(); string petCategoryName=tbEditPetCategoryName.Text.Trim().ToString(); bool isVisible = bool.Parse(cbIsvisible.Checked.ToString()); CTPetCategory tpetcategory = new CTPetCategory(); tpetcategory.petCategoryID = petCategoryID; tpetcategory.petCategoryInfo = petCategoryInfo; tpetcategory.petCategoryName = petCategoryName; tpetcategory.IsVisible = isVisible; PetCategory petcategory = new PetCategory(); int insertStatus = petcategory.EditPetCategory(tpetcategory); if (insertStatus != 0) { LoadData(); Response.Write("<script>alert('update成功!')</script>"); } else { Response.Write("<script>alert('update失败!')</script>"); } }
private void LoadData() { List<CTPetCategory> list = new List<CTPetCategory>(); PetCategory petcategory = new PetCategory(); list=petcategory.GetPetCategoryList(); GridView1.DataSource = list; GridView1.DataKeyNames = new string[] { "petCategoryID" }; GridView1.DataBind(); }