using System; |
using System.Data; |
using System.Configuration; |
using System.Web; |
using System.Web.Security; |
using System.Web.UI; |
using System.Web.UI.WebControls; |
using System.Web.UI.WebControls.WebParts; |
using System.Web.UI.HtmlControls; |
using Telerik.WebControls; |
using System.Collections ; |
|
public partial class _Default : System.Web.UI.Page |
{ |
//Declare a global ArrayList itemsList |
public static ArrayList itemsList; |
|
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!IsPostBack) |
{ |
//initializing the ArrayList itemsList |
itemsList = new ArrayList(); |
//Looping through each node in the Treeview collection |
foreach (RadTreeNode node in RadTreeView1.Nodes) |
{ |
//Adding the node name to the arraylist |
itemsList.Add(node.Text); |
//Looping through the child nodes |
for (int i = 0; i < node.Nodes.Count; i++) |
{ |
//Adding the child node to the arraylist |
itemsList.Add(node.Nodes[i].Text); |
} |
} |
//Populating the combobox |
PopulateCombo(); |
} |
|
} |
//Function for populating the RadCombobox |
private void PopulateCombo() |
{ |
RadComboBox1.DataSource = itemsList; |
RadComboBox1.DataBind(); |
} |
|
//Button click event handler |
protected void Button1_Click(object sender, EventArgs e) |
{ |
//Getting the text entered in the textbox |
string treeNode = TextBox1.Text; |
//Passing the node name entered in the Textbox to the FindTreeNode function for finding the treenode |
FindTreeNode(treeNode); |
} |
//FindTreeNode function |
private void FindTreeNode(String treeNode) |
{ |
//Looping through each node in the treeview |
foreach (RadTreeNode node in RadTreeView1.Nodes) |
{ |
//Checking the node name with the node name entered in the textbox |
if (node.Text == treeNode) |
{ |
//if the node name equal to the node name entered in the textbox setting the selected property of the node to true |
node.Selected = true; |
} |
else |
{ |
node.Selected = false; |
} |
//Looping through the child nodes |
for (int i = 0; i < node.Nodes.Count; i++) |
{ |
if (node.Nodes[i].Text == treeNode) |
{ |
//if the node name equal to the node name entered in the textbox setting the selected property of the node to true and expanding that node. |
node.Expanded = true; |
node.Nodes[i].Selected = true; |
} |
else |
{ |
node.Nodes[i].Selected = false; |
} |
} |
} |
} |
|
protected void RadComboBox1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) |
{ |
//getting the selected item from the RadCombobox |
String treeNode = RadComboBox1.SelectedItem.Text; |
//Passing the selected item to the "FIndTreeNode" function. |
FindTreeNode(treeNode); |
} |
} |
|