asp.net treeView 動態增加節點、編輯節點、刪除節點

來源:互聯網
上載者:User

<%
/*
這是一款asp教程.net treeview 動態增加節點、編輯節點、刪除節點功能,下面我們第一個執行個體是講增加節點的單一功能,後來是具體的舉例說是哦treeview動態增加節點、編輯節點、刪除節點功能吧。
*/
//treeview節點seletedindexchange中顯示資料修改儲存
  protected void treeview1_selectednodechanged(object sender, eventargs e)
  {
  if (this.treeview1.selectednode != null)
  {
  string xtbh = this.treeview1.selectednode.value.trim();
  if (this.treeview1.selectednode.value.trim() != "0")
  {
  this.hd_xtbh.value = xtbh;
  dataset ds = this.getjgxx(xtbh, false);
  if (ds.tables[0].rows.count > 0)
  {
  txtbmmc.text = ds.tables[0].rows[0]["jigmc"].tostring();
  txtbmbh.text = ds.tables[0].rows[0]["jigbh"].tostring();
  }
  }
  else
  {
  txtbmbh.text = "";
  txtbmmc.text =treeview1.selectednode.text.trim();
  }
  }
  }
 
//執行個體方法
using system;
using system.collections;
using system.configuration;
using system.data;
using system.linq;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.htmlcontrols;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.xml.linq;
using mycontent.model;
using mycontent.bll;
using system.collections.generic;

public partial class admin_dianpu_dianputypemanager : system.web.ui.page
{
  protected void page_load(object sender, eventargs e)
  {
  if (!ispostback)
  {
  if (request.querystring.count != 0)
  {
  int id = convert.toint32(request.querystring["id"].tostring());
  leixing tp = leixingmanager.getleixingbyid(id);
  this.txtname.text = tp.tname;
  }
  bindtypebig();
  showtreeview();
  }
  }
  //填充dropdownlist行業類型
  public void bindtypebig()
  {
  ilist<leixing> comps教程 = leixingmanager.getallleixingbytid(0);
  this.ddlalltype.items.add("請選擇");
  foreach (leixing compt in comps)
  {
  listitem item = new listitem();
  item.value = compt.tid.tostring();
  item.text = compt.tname;
  this.ddlalltype.items.add(item);
  }
  }
  //填充treevview
  public void showtreeview()
  {
  ilist<leixing> lists = leixingmanager.getallleixingbytid(0);
  foreach (leixing item in lists)
  {
  //建立父節點
  treenode father = this.createtreenode(item.tname, item.tid.tostring(), "dianputypemanager.aspx?id=" + item.tid, "images/opentree.gif");
  createchildnode(item.tid, father);
  this.tvproducttype.nodes.add(father);
  }
  }
  //建立子節點
  public void createchildnode(int typeid, treenode fathernode)
  {
  ilist<leixing> lists = leixingmanager.getallleixingbytid(typeid);
  foreach (leixing item in lists)
  {
  treenode child = this.createtreenode(item.tname, item.tid.tostring(), "dianputypemanager.aspx?id=" + item.tid, "images/opentree.gif");
  createchildnode(item.tid, child);
  addtree(fathernode, child);
  }
  }
  //把子節點加入父節點
  private void addtree(treenode father, treenode child)
  {
  father.childnodes.add(child);
  }
  //建立樹的節點
  public treenode createtreenode(string name, string id, string url, string img)
  {
  treenode node = new treenode();
  node.text = name;
  node.value = id;
  node.navigateurl = url;
  node.imageurl = img;
  return node;
  }
  protected void btnupdate_click(object sender, eventargs e)
  {
  if (this.ddlalltype.text == "請選擇")
  {
  if (this.txtname.text.trim() == "")
  {
  scriptmanager.registerclientscriptblock(page, this.gettype(), "", "alert('修改時,類型名不可為空!'),window.location='dianputypemanager.aspx'", true);
  //response.write("<script> alert('修改時,類型名不可為空!');location='dianputypemanager.aspx';</script>");
  }
  else if (this.txtname.text.trim() != "")
  {
  int id = convert.toint32(request.querystring["id"].tostring());//擷取所選的節點id
  if (leixingmanager.updateleixingbynameandid(this.txtname.text.trim().tostring(), id) > 0)
  {
  scriptmanager.registerclientscriptblock(page, this.gettype(), "", "alert('修改成功!'),window.location='dianputypemanager.aspx'", true);
  //response.write("<script> alert('修改成功!');location='dianputypemanager.aspx';</script>");
  }
  else
  {
  scriptmanager.registerclientscriptblock(page, this.gettype(), "", "alert('修改失敗!'),window.location='dianputypemanager.aspx'", true);
  //response.write("<script> alert('修改失敗!');location='dianputypemanager.aspx';</script>");
  }
  }
  }
  else
  {
  if (this.txtname.text.trim() == "")
  {
  scriptmanager.registerclientscriptblock(page, this.gettype(), "", "alert('修改時,類型名不可為空!'),window.location='dianputypemanager.aspx'", true);
  //response.write("<script> alert('修改時,類型名不可為空!');location='dianputypemanager.aspx';</script>");
  }
  else if (this.txtname.text.trim() != "")
  {
  int id = convert.toint32(request.querystring["id"].tostring());//擷取所選的節點id
  int parentid = convert.toint32(this.ddlalltype.selectedvalue.tostring());
  if (leixingmanager.updateleixingbyparentidandid(parentid, id) > 0)
  {
  scriptmanager.registerclientscriptblock(page, this.gettype(), "", "alert('修改成功'),window.location='dianputypemanager.aspx'", true);
  //response.write("<script> alert('修改成功!');location='dianputypemanager.aspx';</script>");
  }
  else
  {
  scriptmanager.registerclientscriptblock(page, this.gettype(), "", "alert('修改失敗!'),window.location='dianputypemanager.aspx'", true);
  //response.write("<script> alert('修改失敗!');location='dianputypemanager.aspx';</script>");
  }
  }
  }

   
  }
  protected void btndelete_click(object sender, eventargs e)
  {
  if (request.querystring["id"].tostring() == null)
  {
  scriptmanager.registerclientscriptblock(page, this.gettype(), "", "alert('刪除時:請選擇刪除項!'),window.location='dianputypemanager.aspx'", true);
  //response.write("<script> alert('刪除時:請選擇刪除項!');location='dianputypemanager.aspx';</script>");
  }
  else
  {
  int id = convert.toint32(request.querystring["id"].tostring());//擷取所選的節點id
  if (leixingmanager.getallleixingbytid(id).count != 0)
  {
  scriptmanager.registerclientscriptblock(page, this.gettype(), "", "alert('請查看相關連結,再行刪除'),window.location='dianputypemanager.aspx'", true);
  //response.write("<script>alert('請查看相關連結,再行刪除');location='dianputypemanager.aspx';</script>");
  }
  else
  {
  if (leixingmanager.deleteleixingbyid(id) > 0)
  {
  scriptmanager.registerclientscriptblock(page, this.gettype(), "", "alert('刪除成功!'),window.location='dianputypemanager.aspx'", true);
  //response.write("<script> alert('刪除成功!');location='dianputypemanager.aspx';</script>");
  }
  else
  {
  scriptmanager.registerclientscriptblock(page, this.gettype(), "", "alert('刪除失敗!'),window.location='dianputypemanager.aspx'", true);
  //response.write("<script> alert('刪除失敗!');location='dianputypemanager.aspx';</script>");
  }
  }
  }
   
  }
   
}

%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.