C # define treeview property programmatically

I am new to C # and ASP.net. In my project I am showing a list of nodes in a treeview control. In my interface I can create a tree view and define its fill method like

<asp:TreeView ID="tv1" runat ="server" ExpandDepth ="2" PopulateNodesFromClient="false" OnTreeNodePopulate="TreeNodePopulate"/>

      

What is the equivalent way of programming it?

tv1.OnTreeNodePopulate = "TreeNodePopulate"; // isn't working

      

Thanks in Advance.

+3


source to share


2 answers


You need to connect TreeView1_TreeNodePopulate to the TreeView control. You can do it declaratively from markup ...

<asp:TreeView ID="TreeView1" runat="server" OnTreeNodePopulate="TreeView1_TreeNodePopulate">

      



or, as needed, from the code behind ...

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    TreeView1.TreeNodePopulate += TreeView1_TreeNodePopulate;
}

      

0


source


You need to subscribe to an event TreeNodePopulate

not set string

, check the code below:

tv1.TreeNodePopulate += TreeView_TreeNodePopulate;

      



and caller method:

void TreeView_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
    // Do your code here
}

      

0


source







All Articles