C# .NET - In Pageload set TreeView node to a value

Asked By Pranay on 11-Mar-13 01:11 PM


TreeNodeBinding tnb = new TreeNodeBinding();


tnb.DataMember =


"System.Data.DataRowView";


tnb.TextField =


"C_Name";


tnb.ValueField =


"CategoryId";


tnb.PopulateOnDemand =


false;


tnb.SelectAction =


TreeNodeSelectAction.Select;


TreeView1.DataBindings.Add(tnb);

 

TreeView1.DataSource =


new HierarchicalDataSet(ds, "CategoryId", "ParentCatId");


TreeView1.DataBind();


 if (!this.IsPostBack)


{

TreeNode node = TreeView1.FindNode(Request.QueryString["Cat"].ToString());

node.Selected = true;

}

I trying to get TreeView node to be selected based on the text of the node being passed from another page. The problem is i'm getting error. In debug mode I see that even after databind I dont see TreeView1 getting populated with nodes but TreeView is displaying everything properly on the webpage. All I want is to highlight the node as selected based on the value from other page
Any help is much appreciated.
Thanks