views:

285

answers:

0

Hi Everybody, I want to expand treeview node and redirect to other page on its node click. How to do that. I have done this in the http://www.wintexindia.com but i have forgot logic. In this site if i click on node it redirects to subcategory page and all child nodes are expanded.

Please Help.

My code is giveb below. protected void ExpendedNode_Change(object sender, TreeNodeEventArgs e) { if (e.Node.Parent == null) { e.Node.NavigateUrl = "~/SubCategory.aspx?Cat_ID=" + e.Node.Value; } else { e.Node.NavigateUrl = "~/Default1.aspx?SubCat_ID=" + e.Node.Value; } }

    protected void CollapsedNode_Change(object sender, TreeNodeEventArgs e)
    {
        if (e.Node.Parent == null)
        {
            e.Node.NavigateUrl = "~/SubCategory.aspx?Cat_ID=" + e.Node.Value;
        }
        else
        {
            e.Node.NavigateUrl = "~/Default1.aspx?SubCat_ID=" + e.Node.Value;
        }
    }

public void FillCategories() { //DataTable dt = new DataTable(); //TreeView1.ExpandImageUrl = "~/Themes/WintexTheme/images/07.gif"; //TreeView1.CollapseImageUrl = "~/Themes/WintexTheme/images/07.gif";

        DataSet ibds3 = new DataSet();


        SqlCommand com = new SqlCommand(" Select Distinct tbl_Category.Cat_Name,tbl_Category.Cat_ID from tbl_Category", ibconn);

        SqlDataAdapter sda = new SqlDataAdapter(com);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        ibconn.Open();
        //com.ExecuteNonQuery();

        //ibds = new DataSet();
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            catid = Convert.ToInt32(dr["Cat_ID"].ToString());               
            TreeNode NewNode = new TreeNode(dr.ItemArray[0].ToString(), dr.ItemArray[1].ToString());
            NewNode.SelectAction = TreeNodeSelectAction.Expand;

            this.TreeView1.Nodes.Add(NewNode);
            NewNode.Expanded = false;

            FillCategorieschild(NewNode);

        }

        ibconn.Close();
        TreeView1.ExpandAll();


    }

    public void FillCategorieschild(TreeNode Node1)
    {
        SqlCommand com = new SqlCommand("SELECT * from tbl_SubCategory  WHERE  tbl_SubCategory.Cat_ID=" + Node1.Value, ibconn);

        SqlDataAdapter sda = new SqlDataAdapter(com);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        //com.ExecuteNonQuery();
        if (ds.Tables[0].Rows.Count != 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                linkid = Convert.ToInt32(dr["SubCat_ID"]);
                TreeNode NewNode1 = new TreeNode(dr.ItemArray[2].ToString(), dr.ItemArray[0].ToString());

                Node1.ChildNodes.Add(NewNode1);

             //   NewNode1.ImageUrl = "~/Themes/smokertheme/images/bullet1.gif";                    

            }
        }

    }