treeview: nodes are adding automatically

Last post 07-06-2009 4:18 AM by demoninside9. 9 replies.

Sort Posts:

  • treeview: nodes are adding automatically

    06-30-2009, 2:27 AM
    • Member
      109 point Member
    • demoninside9
    • Member since 12-20-2007, 8:39 AM
    • New Delhi
    • Posts 716

    Hi all,

              I am having a TreeView on a aspx page. its working fine. I have written following code on TreeView1_SelectedNodeChanged.

            string strSql = "select a.MemberId,a.FirstName,a.LastName,a.Orgnization,a.City from mtblContacts as a INNER JOIN mtblGrpCon as b ON b.MemberId=a.MemberId and b.id=" + TreeView1.SelectedNode.Value + "";
            DataTable dt = new DataTable();
            dt = myCls.My_Datatable(strSql);
            if (dt.Rows.Count > 0)
            {
                Dg.DataSource = dt;
                Dg.DataBind();
            }

    first of all I want to add sql parameters to this code. How to do that.

    Now its working fine on simple .aspx form but when i use masterpage attached to this page ans also having <asp:UpdatePanel id="UpdatePanel1" runat="server">(using ajax)

    then when i click any node or subnode of this treeview, this seems to like there are automatically adding similar nodes to clicked nodes on every click. but in backend from which DB table i bounded this there is no updation regarding nodes adding, means there is no effet to Db table. but on the page on every click it shows like you are adding nodes or subnodes to clicked node.

    what the issue i didn't get.

    let me know pls..

    thanx

    never let you down..always be happy...
  • Re: treeview: nodes are adding automatically

    06-30-2009, 2:50 AM
    • Participant
      1,066 point Participant
    • stevew1975
    • Member since 05-29-2009, 2:51 PM
    • Bristol, UK
    • Posts 189

    check your page_load, are you adding things here, and do you need to wrap this in a !ispostback




    Please mark this post as answered if it helped you!
  • Re: treeview: nodes are adding automatically

    06-30-2009, 2:56 AM
    • Member
      109 point Member
    • demoninside9
    • Member since 12-20-2007, 8:39 AM
    • New Delhi
    • Posts 716

    No its in  postback like


    if (!IsPostBack)

    {

    PopulateRootLevel();

    }


    so it should be like

    if (!IsPostBack)

    {


    }

    PopulateRootLevel();


    thanx

    never let you down..always be happy...
  • Re: treeview: nodes are adding automatically

    06-30-2009, 2:58 AM
    • Participant
      854 point Participant
    • bbalavikram
    • Member since 06-14-2007, 11:30 AM
    • Bangalore
    • Posts 215

     try this. Where ever you are creating the menu, enclose the following code.

                    if (!Page.IsPostBack)
                    {
                        //Write your tree creation code here
                        PopulateRootLevel();
                    }



     I am editing the code after seeing your post

    B.BalaVikram[KingCobra].
  • Re: treeview: nodes are adding automatically

    06-30-2009, 3:06 AM
    • Member
      109 point Member
    • demoninside9
    • Member since 12-20-2007, 8:39 AM
    • New Delhi
    • Posts 716

    I did same as u said

    if (!IsPostBack)
            {
                PopulateRootLevel();
            }


    private void PopulateRootLevel()
        {
            string strSql = "select id,title,(select count(*) FROM mtblTest "
        + "WHERE parentid=sc.id) childnodecount FROM mtblTest sc where parentid IS NULL";
            DataTable dt = new DataTable();
            dt = myCls.My_Datatable(strSql);
            if (dt.Rows.Count > 0)
            {
                PopulateNodes(dt, TreeView1.Nodes);

            }
        }

    same results

    thanx

    never let you down..always be happy...
  • Re: treeview: nodes are adding automatically

    06-30-2009, 10:09 AM
    • Participant
      854 point Participant
    • bbalavikram
    • Member since 06-14-2007, 11:30 AM
    • Bangalore
    • Posts 215

     Are you sure that you are not calling the "PopulateRootLevel();" any where else in the page ????

    B.BalaVikram[KingCobra].
  • Re: treeview: nodes are adding automatically

    06-30-2009, 11:59 PM
    • Member
      109 point Member
    • demoninside9
    • Member since 12-20-2007, 8:39 AM
    • New Delhi
    • Posts 716

    Yea I am sure, i m not using PopulateRootLevel() in other place on the page.

    never let you down..always be happy...
  • Re: treeview: nodes are adding automatically

    07-02-2009, 10:47 PM
    Answer

    Have you assign any URLs to the NavigateUrl property of the TreeNode?

    Hong-Gang Chen
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: treeview: nodes are adding automatically

    07-06-2009, 3:51 AM
    • Participant
      854 point Participant
    • bbalavikram
    • Member since 06-14-2007, 11:30 AM
    • Bangalore
    • Posts 215

    Missed this really.

    Any control be it treeview nodes, link button..  that has the property NavigateURL and not being set makes the page the Postback twice even if there was only one event to make the postback.

    Good guess Hong-Gang Chen

    B.BalaVikram[KingCobra].
  • Re: treeview: nodes are adding automatically

    07-06-2009, 4:18 AM
    • Member
      109 point Member
    • demoninside9
    • Member since 12-20-2007, 8:39 AM
    • New Delhi
    • Posts 716

    I am binding treeview to DB. I dont need NavigateURL property. it auto link from DB. Then why should i set this property? if its nessasary then what should i set to this property.

    thanx

    never let you down..always be happy...
Page 1 of 1 (10 items)
Microsoft Communities