zoukankan      html  css  js  c++  java
  • TreeView

    今天做项目用到了TreeView。

    这是绑定:

    View Code
     1 public void Bind()
    2 {
    3 DataTable dt = UserDAL.GetRole("and parentid=0 ");
    4 tvShow.ShowCheckBoxes = TreeNodeTypes.All;
    5 for (int i = 0; i < dt.Rows.Count; i++)
    6 {
    7 TreeNode nd = new TreeNode();
    8 nd.ShowCheckBox = true;
    9 nd.Text = dt.Rows[i]["FuncName"].ToString();
    10 nd.Value = dt.Rows[i]["FuncId"].ToString();
    11 DataTable dt2 = UserDAL.GetRole(" and parentid=" + Convert.ToInt32(nd.Value) + "");
    12
    13 for (int j = 0; j < dt2.Rows.Count; j++)
    14 {
    15 TreeNode tn = new TreeNode();
    16 tn.ShowCheckBox = true;
    17 tn.Text = dt2.Rows[j]["FuncName"].ToString();
    18 tn.Value = dt2.Rows[j]["FuncId"].ToString();
    19 nd.ChildNodes.Add(tn);
    20 }
    21 tvShow.Nodes.Add(nd);
    22 }
    23 }

    这是获取(递归):

    View Code
     1 public void bbs(TreeNodeCollection coll)
    2 {
    3 DataTable dt = UserDAL.GetGrpFuncList(int.Parse(ViewState["userid"].ToString()));
    4 foreach (TreeNode aas in coll)
    5 {
    6 for (int i = 0; i < dt.Rows.Count; i++)
    7 {
    8 if (Convert.ToInt32(aas.Value) == Convert.ToInt32(dt.Rows[i]["funcid"].ToString()))
    9 {
    10 aas.Checked = true;
    11 }
    12 }
    13 bbs(aas.ChildNodes);
    14 }
    15 }
  • 相关阅读:
    UVA 254 Towers of Hanoi
    UVA 701 The Archeologists' Dilemma
    UVA 185 Roman Numerals
    UVA 10994 Simple Addition
    UVA 10570 Meeting with Aliens
    UVA 306 Cipher
    UVA 10160 Servicing Stations
    UVA 317 Hexagon
    UVA 10123 No Tipping
    UVA 696 How Many Knights
  • 原文地址:https://www.cnblogs.com/tony312ws/p/2127226.html
Copyright © 2011-2022 走看看