treeview控件 放在updatepanel中  点击节点还是刷新???

解决方案 »

  1.   

     string sql = "select * from T_newstype where T_type=0";
                DataSet ds = Code.DB.Serchtb(sql, "newstype");
                for (int i = 0; i < ds.Tables["newstype"].Rows.Count; i++)
                {
                    TreeNode tn = Code.Comm.Outtree(ds.Tables["newstype"].Rows[i]["T_id"].ToString(), ds.Tables["newstype"].Rows[i]["T_name"].ToString());
                    this.NewsTree.Nodes.Add(tn);
                    DataSet dsxl = Code.DB.Serchtb("select * from T_newstype where T_type='" + tn.Value + "'", "newstypexl");
                    for (int j = 0; j < dsxl.Tables["newstypexl"].Rows.Count; j++)
                    {
                        TreeNode tnxl = Code.Comm.Outtree(dsxl.Tables["newstypexl"].Rows[j]["T_id"].ToString(), dsxl.Tables["newstypexl"].Rows[j]["T_name"].ToString());
                        tn.ChildNodes.Add(tnxl);
                    }
                }
      

  2.   

    什么都不用:
    http://dazhzp.cn/logonx.aspx?id=0你试下吧
    再不明,看下msdn吧
      

  3.   

     <asp:TreeView ID="TVProduct" runat="server" OnSelectedNodeChanged="TVProduct_SelectedNodeChanged"
                        Height="100%" ImageSet="Faq">
                        <ParentNodeStyle Font-Bold="False" ImageUrl="~/images/2.png" />
                        <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
                        <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px"
                            ImageUrl="~/image/0.png" VerticalPadding="0px" />
                        <RootNodeStyle ImageUrl="~/images/1.png" />
                        <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px"
                            ImageUrl="~/images/3.png" NodeSpacing="0px" VerticalPadding="1px" />
                    </asp:TreeView>
      

  4.   

    public partial class Control_left_Product : System.Web.UI.UserControl
    {
        TreeNode root = new TreeNode();
        TreeNode leaf = new TreeNode();
        TreeNode subleaf = new TreeNode();
        List<Model.ProductType> lists;
        List<Model.GrassType> list; 
        protected void Page_Load(object sender, EventArgs e)
        {        if (!Page.IsPostBack)
            {
                BindTreeView();
            }
        }
        public void BindTreeView()
        {        if (TVProduct.Nodes.Count == 0)
            {
                root.Text = "产品类别";
                root.Value = "0";
                TVProduct.Nodes.Add(root);
                TVProduct.ExpandAll();
            }
             lists = new BLL.ProductType().Select("");
            
            foreach (Model.ProductType model in lists)   //treeview加载大类别
            {
                leaf = new TreeNode();
                leaf.Text = model.Type_Name;
                leaf.Value =model.Type_Id.ToString();
                root.ChildNodes.Add(leaf);
                BindSubLeaf(model.Type_Id);
                leaf.Collapse();
                
            }
             
        }    public void BindSubLeaf(int Pro_TypeId)  //绑定子节点,展开后每一类最后一个节点(treeview加载小类别)
        {
             list = new BLL.GrassType().Selects(Pro_TypeId);
            foreach (Model.GrassType models in list)
            {
                subleaf = new TreeNode();
                subleaf.Text = models.Type_Name;
                subleaf.Value = models.Type_Id.ToString();
                leaf.ChildNodes.Add(subleaf);
                
              
            }
        }
        protected void TVProduct_SelectedNodeChanged(object sender, EventArgs e)
        {
            string NodesName = TVProduct.SelectedNode.Text;  //选择当前节点
            if (TVProduct.SelectedNode.ChildNodes.Count!=0)   //判断子节点下面没有节点
            {
                
                lists = new BLL.ProductType().Select("");
                foreach (Model.ProductType Pro_Model in lists)
                {
                    if (NodesName == Pro_Model.Type_Name)
                    {
                        int Pro_TypeId = Pro_Model.Type_Id;
                        Session["Pro_TypeId"] = Pro_TypeId;
                        Session["Gra_TypeId"] = 0;
                        Response.Redirect("Products.aspx?siteMapName="+NodesName);
                        
                    }
                }
            }
            else
            {
                string NodesParent = TVProduct.SelectedNode.Parent.Text;  //当前节点的父节点
                lists = new BLL.ProductType().Select("");
                foreach (Model.ProductType Pro_Models in lists)
                {
                    if (NodesParent == Pro_Models.Type_Name)
                    {
                        int Pro_TypeId = Pro_Models.Type_Id;
                        Session["Pro_TypeId"] = Pro_TypeId;
                    }
                }
                list = new BLL.GrassType().Select("");
                foreach (Model.GrassType Grass_Model in list)
                {
                    if (NodesName == Grass_Model.Type_Name)
                    {
                        TVProduct.SelectedNode.Parent.ToggleExpandState();
                        int Gra_TypeId = Grass_Model.Type_Id;
                        Session["Gra_TypeId"] = Gra_TypeId;
                        Response.Redirect("Products.aspx?siteMapName=" + NodesName + "&NodesParent=" + NodesParent);  
                    }
                }
                        }
    }    }
      

  5.   

    updatepanel1呢?
    如果你用的是ASP。NETR 2。0需要在ScriptManger中显示声明,允许局部刷新 。
      

  6.   

    放在 updatel1 中 有ScriptManger显示声明!!!
      

  7.   

    动态绑定的treeview节点,刷新无法避免,除非用js读取和绑定数据
      

  8.   

    无刷新就用JS来实现吧this.TreeView1.Attributes.Add("onclick ", "GetTitle();return false "); 
    [code=HTML][    <script type="text/javascript">
            function GetTitle() {
                var Obj = event.srcElement;
                alert(Obj.innerText);
            }    </script>/code]
      

  9.   

    上个前台JS弄乱了    <script type="text/javascript">
            function GetTitle() {
                var Obj = event.srcElement;
                alert(Obj.innerText);
            }    </script>