zoukankan      html  css  js  c++  java
  • 绑定 treeview树

     一 : 

    效果

    <form id="form1" runat="server">
    <asp:TreeView ID="TreeView1" runat="server" Height="300px" Width="200px" SelectAction="Expand">
    </asp:TreeView>
    </form>

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!this.IsPostBack)
    {
    string where = " AND Com_IsTrue=0 AND Com_Status=2 ";
    BDTree(where);
    }
    }

    private List<T_CommodityType> list = new List<T_CommodityType>();
    private void BDTree( string where )
    {
    list = bll.GetModelList(where );
    AddTree("", null);
    }

    public void AddTree(string ParentID, TreeNode pNode)
    {
    if (list.Where(o => o.Com_ParentId.ToString().Equals(ParentID)).Count() == 0)
    return;
    List<T_CommodityType> clist = list.Where(o => o.Com_ParentId.ToString().Equals(ParentID)).ToList();
    foreach (T_CommodityType dc in clist)
    {
    TreeNode Node = new TreeNode();
    if (pNode == null)
    {
    Node.Value = dc.Com_Id.ToString();
    Node.Text = dc.Com_Name;
    Node.NavigateUrl = "javascript:SaveSelData('" + Node.Text + "','" + Node.Value + "');";
    TreeView1.Nodes.Add(Node);
    AddTree(dc.Com_Id.ToString(), Node);
    }
    else
    {
    Node.Value = dc.Com_Id.ToString();
    Node.Text = dc.Com_Name;
    Node.NavigateUrl = "javascript:SaveSelData('" + Node.Text + "','" + Node.Value + "');";
    pNode.ChildNodes.Add(Node);
    AddTree(dc.Com_Id.ToString(), Node);
    }
    }
    }

     二 :

    点击 “水果类”

    <div>
    <asp:TreeView ID="TreeView1" runat="server" Height="300px" Width="200px" SelectAction="Expand"
    ShowCheckBoxes="All" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged" OnLoad="TreeView1_Load">
    </asp:TreeView>
    </div>

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    BDTree();
    }
    }
    private List<T_CommodityType> list = new List<T_CommodityType>();
    private void BDTree()
    {
    list = bll.GetModelList(" AND Com_IsTrue=0 AND Com_Status=2 ; ");
    AddTree("00000000-0000-0000-0000-000000000000", null);
    }
    public void AddTree(string ParentID, TreeNode pNode)
    {
    if (list.Where(o => o.Com_ParentId.ToString().Equals(ParentID)).Count() == 0)
    return;
    List<T_CommodityType> clist =
    list.Where(o => o.Com_ParentId.ToString().ToLower().Equals(ParentID.ToLower())).ToList();
    foreach (T_CommodityType dc in clist)
    {
    TreeNode Node = new TreeNode();
    if (pNode == null)
    {
    Node.Value = dc.Com_Id.ToString();
    Node.Text = dc.Com_Name;
    Node.ShowCheckBox = true;
    TreeView1.Nodes.Add(Node);
    AddTree(dc.Com_Id.ToString(), Node);
    }
    else
    {
    Node.Value = dc.Com_Id.ToString();
    Node.Text = dc.Com_Name;
    Node.ShowCheckBox = true;
    //Node.SelectAction = TreeNodeSelectAction.SelectExpand;
    pNode.ChildNodes.Add(Node);
    AddTree(dc.Com_Id.ToString(), Node);
    }

    }
    }
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
    if (TreeView1.SelectedNode.Checked)
    {
    TreeView1.SelectedNode.Checked = false;
    if (TreeView1.SelectedNode.ChildNodes.Count > 0)
    {
    foreach (TreeNode n in TreeView1.SelectedNode.ChildNodes)
    {
    n.Checked = true;
    }
    }
    return;
    }
    TreeView1.SelectedNode.Checked = true;

    if (TreeView1.SelectedNode.ChildNodes.Count > 0)
    {
    foreach (TreeNode n in TreeView1.SelectedNode.ChildNodes)
    {
    n.Checked = true;
    }
    }
    if (TreeView1.SelectedNode.Parent != null)
    {
    // TreeView1.SelectedNode.Parent.Checked = true;
    }
    }

    protected void TreeView1_Load(object sender, EventArgs e)
    {
    if (!object.Equals(null, TreeView1.SelectedNode))
    {
    TreeView1.SelectedNode.Select();
    TreeView1.SelectedNode.Selected = false;
    }
    }

  • 相关阅读:
    为什么obj不等于obj?
    前端基础:深入理解内存空间
    微信小程序之富文本解析
    微信小程序加载更多 点击查看更多
    目前为止最全的微信小程序项目实例
    小程序图文列表一行俩列
    关于小程序 scroll-view 左右横向滑动没有效果(无法滑动)问题
    微信小程序商品筛选,侧方弹出动画选择页面
    小程序-带参跳转页面
    css-background-image 背景图片太大或太小
  • 原文地址:https://www.cnblogs.com/lk516924/p/4026742.html
Copyright © 2011-2022 走看看