TreeView控件查询. [英] TreeView Control query.

查看:145
本文介绍了TreeView控件查询.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我正在尝试创建一个Treeview函数,该函数根据我给它的值突出显示一个节点.

该页面从会话中加载数据,如果该会话不为空,则从该会话中加载NodeID并突出显示它.如果会话为空,则它是第一次使用,因此它等待使用以下功能对其进行设置

首先在此处设置NodeID的onClick函数由另一个函数放入会话中:

Basically I am trying to create a Treeview function that highlights a node based off a value I give it.

The page loads data from a session and if that session isnt empty it loads the NodeID from the session and highlights it. If the session is empty its the first use so it waits for an input to set it using the function below

The onClick function that first sets the NodeID here, which is put into a session by another function:

protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{    

TreeView1.SelectedNodeStyle.BackColor = System.Drawing.Color.LightGreen;
dbSession.NodeID = Convert.ToInt32(TreeView1.SelectedNode.Value.ToString());
           
}


而且我必须使treeview控件保持与此接近,因为treeview是通过查看数据库表生成的,并获得了订单(我已经设置好了)



and I have to keep my treeview control close to this, as the treeview is generated by looking into a database table and gets the order out ( I already have this set up)


<asp:TreeView ID="TreeView1" runat="server" onselectednodechanged="TreeView1_SelectedNodeChanged" Font-Size="Large" Height="272px" Width="269px">






我需要建议的功能将使用NodeID并从该数字中选择Treeview Control节点并突出显示它.

任何建议如何做到这一点?我一直未能找到有关从ID变量中选择节点"的任何信息,而不是单击然后突出显示该节点






The function I need advise on would take the NodeID and select the Treeview Control node from that number and highlight it.

Any advise on how this is done? I''ve been unsuccessful in finding any information on "Selecting a node from an ID Variable" instead of on click then highlighting that node

推荐答案

您好,您可以存储值,而不是在会话中搜索所选节点的ID,然后根据会话中存储的值选择/突出显示该节点.

请参见下面的代码:树形视图HTML
Hi you can store the value instead of searching for id of the selected node in session and select/highlight the node based on the value stored in session.

Please see below code: tree view HTML
<div>
       <asp:treeview id="Treeview1" runat="server" xmlns:asp="#unknown">
           <nodes>
               <asp:treenode text="Type">
                   <asp:treenode value="IN" text="Inpatient"></asp:treenode>
                   <asp:treenode text="Outpatient"></asp:treenode>
               </asp:treenode>
           </nodes>
       </asp:treeview>
   </div>


参见下面的代码.我在会话和页面加载中存储了一个值,正在树中进行迭代,找出具有相同值的节点,然后选择该值.


See below code behind. I have stored one value in session and in page load i am iterating through the tree and finding out the node having the same value and then making that one selected.

protected void Page_Load(object sender, EventArgs e)
    {
        Session["selValue"] = "IN";
        TreeNodeCollection col =  Treeview1.Nodes;
        highlightNode(col);
    }

    private void highlightNode(TreeNodeCollection col)
    {
        foreach (TreeNode node in col)
        {
            if (node.ChildNodes.Count > 0)
            {
                highlightNode(node.ChildNodes);
            }
            if (node.Value.Trim().ToUpper() == Session["selValue"].ToString().Trim().ToUpper())
            {
                node.Selected = true;
                node.Expanded = true;
                break;
            }
        }
    }


请参见下面的javascript代码,以突出显示选定的节点.


See the below javascript code in order to highlight the selected node.

var HighlightSelectedRow = function ( ){
  var selId =


("
("[ID


= _ SelectedNode]" ).val();
=_SelectedNode]").val();


这篇关于TreeView控件查询.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆