Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code, but when I expand the node data is not displaying, but every thing is working fine. What is the problem, in which event I should write?
C#
protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
   {
       Response.Write(e.Node.Text + "-" + e.Node.Value);
       DataSet dsAllYearEventIDs = obj.GetCompanyID(e.Node.Text);

       DataTable dt1 = dsAllYearEventIDs.Tables[0];
       TreeNode year = (TreeNode)TreeView1.FindNode("year");
       year = new TreeNode();
       year.PopulateOnDemand = true;

       TreeNode yearchild = new TreeNode();
       yearchild.PopulateOnDemand = true;
       yearchild.SelectAction = TreeNodeSelectAction.None;
       yearchild.Text = "<u style='text-style:italic;'>" + "Clinical Events with current guidance of year " + e.Node.Text + "</u>";

       year.ChildNodes.Add(yearchild);
       StringBuilder sbyear = new StringBuilder();
       sbyear.AppendLine("<table style='border:1px solid gray;' width='100%'>");
       for (int j = 0; j < dt1.Rows.Count; j++)
       {
           DataSet dsAllDescription = obj.GetTickerEventDescription(dt1.Rows[j]["Company_ID"].ToString());
           DataTable dt2 = new DataTable();
           dt2 = dsAllDescription.Tables[0];

           sbyear.AppendLine("<tr>");
           sbyear.AppendLine("<td style='width:120px; border:0px dotted gray;'>");
           sbyear.AppendLine("<a href='" + "Ticker.aspx?tick=" + dt2.Rows[0][0].ToString() + "'><b>" + dt2.Rows[0][0].ToString() + "</b></a>");
           sbyear.AppendLine("</td>");
           sbyear.AppendLine("<td style='width:120px; border:0px dotted gray;'>");
           sbyear.AppendLine(dt2.Rows[0][1].ToString());
           sbyear.AppendLine("</td>");
           sbyear.AppendLine("<td style='width:180px; border:0px dotted gray;'>");
           sbyear.AppendLine(dt2.Rows[0][2].ToString());
           sbyear.AppendLine("</td>");
           sbyear.AppendLine("</tr>");
       }
       sbyear.AppendLine("</table>");
       TreeNode childnode = new TreeNode();
       childnode.PopulateOnDemand = true;
       childnode.SelectAction = TreeNodeSelectAction.None;
       childnode.Text = sbyear.ToString();
       year.ChildNodes.Add(childnode);
   }


I have tried by this event also
C#
protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
    {
        DataSet dsAllYearEventIDs = obj.GetCompanyID(e.Node.Text);

        DataTable dt1 = dsAllYearEventIDs.Tables[0];
        TreeNode year = (TreeNode)TreeView1.FindNode("year");
        year = new TreeNode();
         year.PopulateOnDemand = false;
        TreeNode yearchild = new TreeNode();
          yearchild.PopulateOnDemand = false;
        yearchild.SelectAction = TreeNodeSelectAction.None;
        yearchild.Text = "<u style='text-style:italic;'>" + "Clinical Events with current guidance of year " + e.Node.Text + "</u>";

        year.ChildNodes.Add(yearchild);
        StringBuilder sbyear = new StringBuilder();
        sbyear.AppendLine("<table style='border:1px solid gray;' width='100%'>");
        for (int j = 0; j < dt1.Rows.Count; j++)
        {
            DataSet dsAllDescription = obj.GetTickerEventDescription(dt1.Rows[j]["Company_ID"].ToString());
            DataTable dt2 = new DataTable();
            dt2 = dsAllDescription.Tables[0];

            sbyear.AppendLine("<tr>");
            sbyear.AppendLine("<td style='width:120px; border:0px dotted gray;'>");
            sbyear.AppendLine("<a href='" + "Ticker.aspx?tick=" + dt2.Rows[0][0].ToString() + "'><b>" + dt2.Rows[0][0].ToString() + "</b></a>");
            sbyear.AppendLine("</td>");
            sbyear.AppendLine("<td style='width:120px; border:0px dotted gray;'>");
            sbyear.AppendLine(dt2.Rows[0][1].ToString());
            sbyear.AppendLine("</td>");
            sbyear.AppendLine("<td style='width:180px; border:0px dotted gray;'>");
            sbyear.AppendLine(dt2.Rows[0][2].ToString());
            sbyear.AppendLine("</td>");
            sbyear.AppendLine("</tr>");
        }
        sbyear.AppendLine("</table>");
        TreeNode childnode = new TreeNode();
        childnode.PopulateOnDemand = false;
        childnode.SelectAction = TreeNodeSelectAction.None;
        childnode.Text = sbyear.ToString();
        year.ChildNodes.Add(childnode);
    }

To make it work what change I should do in the above code?

PageLoad Code::
C#
EventManager obj = new EventManager();
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {         
            TreeView1.CollapseAll();           
        }
    }
Posted
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900