Urgent: ASP.NET C# problem

Filed Under mercialleasing.com |

  • 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


    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........


  • its it 1.1 or 2.0 ?


  • It is 2.0
    OK thx for ur reply.........
    I hav solved it, here was the mistake

    parentnode.SelectAction = TreeNodeSelectAction.Expand;

    instead of this it shud b

    parentnode.SelectAction = TreeNodeSelectAction.Select;


    Anyway thx again 4 ur reply........







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Urgent: ASP.NET C# problem , Please add it free.

    Comments