n2casey
Super Hero - Super Powers
I m programming for a tree control using asp.net and c# but facing a problem that SelectedNodeChanged event is not raised when I clicks on a node. Here is my code
I have set the OnTreeNodePopulate="PopulateTree" but selectedNodeChanged event is not working. Help me as soon as possible.....
Thx in advance........
Code:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void PopulateTree(object sender, TreeNodeEventArgs e)
{
if (e.Node.ChildNodes.Count == 0)
switch (e.Node.Depth)
{
case 0:
PopulateParent(e.Node);
break;
case 1:
PopulateChild(e.Node);
break;
}
}
protected void PopulateParent(TreeNode node)
{
string sqlqry = "SELECT * FROM TblTreeView WHERE ParentID = 0";
DataSet dset = new DataSet();
dset = GetData(sqlqry);
if (dset.Tables.Count > 0)
foreach (DataRow row in dset.Tables[0].Rows)
{
TreeNode parentnode = new TreeNode(row["Subject"].ToString(), row["MessageID"].ToString());
parentnode.PopulateOnDemand = true;
parentnode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(parentnode);
parentnode.Collapse();
}
}
protected void PopulateChild(TreeNode node)
{
string sqlqry = "SELECT * FROM TblTreeView where ParentID = '" + node.Value + "'";
DataSet dset = new DataSet();
dset = GetData(sqlqry);
if (dset.Tables.Count > 0)
foreach (DataRow row in dset.Tables[0].Rows)
{
TreeNode childnode = new TreeNode(row["Subject"].ToString(), row["ParentId"].ToString());
childnode.PopulateOnDemand = true;
childnode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(childnode);
}
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
string str = TreeView1.Nodes[0].Value;
}
}
protected DataSet GetData(string sqlqry)
{
string constr = "Server=ServerName; Database=DB; User ID=UI; Password=PSWD";
SqlConnection sqlcon = new SqlConnection(constr);
SqlCommand sqlcom = new SqlCommand(sqlqry, sqlcon);
SqlDataAdapter sqladap = new SqlDataAdapter(sqlcom);
DataSet dset = new DataSet();
sqladap.Fill(dset);
return dset;
}
I have set the OnTreeNodePopulate="PopulateTree" but selectedNodeChanged event is not working. Help me as soon as possible.....
Thx in advance........