Switch data source of TreeView

Discussion in 'ASP .Net Web Controls' started by Mark Goldin, Jan 29, 2004.

  1. Mark Goldin

    Mark Goldin Guest

    I have a TreeView control and two radiobuttons on my Web form.
    I want to change data source (XML file) of the tree when the user clicks
    on buttons.
    Here is Codebehind the buttons:
    private void RadioButton1_CheckedChanged(object sender, System.EventArgs e)

    {

    TreeView1.TreeNodeSrc = "data.xml";

    }

    private void Radiobutton2_CheckedChanged(object sender, System.EventArgs e)

    {

    TreeView1.TreeNodeSrc = "charttreexslt.xml";

    }

    Autopostback is enabled for both.

    Nothing happens when I select either button.

    What am I missing here?
    Mark Goldin, Jan 29, 2004
    #1
    1. Advertising

  2. Mark Goldin

    CMA Guest

    hi mark again,

    i dont know whether u r using a grouped check boxes. means when i select
    1st, the second one automatically unselect. when i select 2nd, 1st will
    unselect.
    if it is grouped....
    the problem is, always BOTH methods will execute since all two radio buttons
    changed the checked property. so the finally executed one will show to u.

    solution.
    use a radio button list, in the selected index changed.. u can search for
    the selected item and load the XML depending on the selection.

    else in the RadioButton1_CheckedChanged().. (code in the bottom)
    check for the checked property and bind the XML only if checked....

    hope this helps,
    CMA


    "Mark Goldin" <> wrote in message
    news:...
    > I have a TreeView control and two radiobuttons on my Web form.
    > I want to change data source (XML file) of the tree when the user clicks
    > on buttons.
    > Here is Codebehind the buttons:
    > private void RadioButton1_CheckedChanged(object sender, System.EventArgs

    e)
    >
    > {
    >
    > TreeView1.TreeNodeSrc = "data.xml";
    >
    > }
    >
    > private void Radiobutton2_CheckedChanged(object sender, System.EventArgs

    e)
    >
    > {
    >
    > TreeView1.TreeNodeSrc = "charttreexslt.xml";
    >
    > }
    >
    > Autopostback is enabled for both.
    >
    > Nothing happens when I select either button.
    >
    > What am I missing here?
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    CMA, Jan 30, 2004
    #2
    1. Advertising

  3. Mark Goldin

    Mark Goldin Guest

    OK,
    I modified code like this:
    private void RadioButton1_CheckedChanged(object sender, System.EventArgs e)

    {

    if (this.RadioButton1.Checked == true)

    TreeView1.TreeNodeSrc = "data.xml";

    }

    private void Radiobutton2_CheckedChanged(object sender, System.EventArgs e)

    {

    if (this.Radiobutton2.Checked == true)

    TreeView1.TreeNodeSrc = "charttreexslt.xml";

    }

    It still does not work.

    "CMA" <> wrote in message
    news:#...
    > hi mark again,
    >
    > i dont know whether u r using a grouped check boxes. means when i select
    > 1st, the second one automatically unselect. when i select 2nd, 1st will
    > unselect.
    > if it is grouped....
    > the problem is, always BOTH methods will execute since all two radio

    buttons
    > changed the checked property. so the finally executed one will show to u.
    >
    > solution.
    > use a radio button list, in the selected index changed.. u can search for
    > the selected item and load the XML depending on the selection.
    >
    > else in the RadioButton1_CheckedChanged().. (code in the bottom)
    > check for the checked property and bind the XML only if checked....
    >
    > hope this helps,
    > CMA
    >
    >
    > "Mark Goldin" <> wrote in message
    > news:...
    > > I have a TreeView control and two radiobuttons on my Web form.
    > > I want to change data source (XML file) of the tree when the user clicks
    > > on buttons.
    > > Here is Codebehind the buttons:
    > > private void RadioButton1_CheckedChanged(object sender, System.EventArgs

    > e)
    > >
    > > {
    > >
    > > TreeView1.TreeNodeSrc = "data.xml";
    > >
    > > }
    > >
    > > private void Radiobutton2_CheckedChanged(object sender, System.EventArgs

    > e)
    > >
    > > {
    > >
    > > TreeView1.TreeNodeSrc = "charttreexslt.xml";
    > >
    > > }
    > >
    > > Autopostback is enabled for both.
    > >
    > > Nothing happens when I select either button.
    > >
    > > What am I missing here?
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >

    >
    >
    Mark Goldin, Jan 30, 2004
    #3
  4. Mark Goldin

    Mark Goldin Guest

    I have modifed code.
    Now I am calling same function for both buttons:
    private void TreeType_CheckedChanged(object sender, System.EventArgs e)

    {

    if (this.RadioButton1.Checked == true)

    this.TreeView1.TreeNodeSrc = "data.xml";

    if (this.Radiobutton2.Checked == true)

    this.TreeView1.TreeNodeSrc = "charttreexslt.xml";

    Response.Write(this.TreeView1.TreeNodeSrc);

    }

    Response shows that data souece has been changed properly but the tree shows
    same data all the time.

    Any idea?

    "CMA" <> wrote in message
    news:#...
    > hi mark again,
    >
    > i dont know whether u r using a grouped check boxes. means when i select
    > 1st, the second one automatically unselect. when i select 2nd, 1st will
    > unselect.
    > if it is grouped....
    > the problem is, always BOTH methods will execute since all two radio

    buttons
    > changed the checked property. so the finally executed one will show to u.
    >
    > solution.
    > use a radio button list, in the selected index changed.. u can search for
    > the selected item and load the XML depending on the selection.
    >
    > else in the RadioButton1_CheckedChanged().. (code in the bottom)
    > check for the checked property and bind the XML only if checked....
    >
    > hope this helps,
    > CMA
    >
    >
    > "Mark Goldin" <> wrote in message
    > news:...
    > > I have a TreeView control and two radiobuttons on my Web form.
    > > I want to change data source (XML file) of the tree when the user clicks
    > > on buttons.
    > > Here is Codebehind the buttons:
    > > private void RadioButton1_CheckedChanged(object sender, System.EventArgs

    > e)
    > >
    > > {
    > >
    > > TreeView1.TreeNodeSrc = "data.xml";
    > >
    > > }
    > >
    > > private void Radiobutton2_CheckedChanged(object sender, System.EventArgs

    > e)
    > >
    > > {
    > >
    > > TreeView1.TreeNodeSrc = "charttreexslt.xml";
    > >
    > > }
    > >
    > > Autopostback is enabled for both.
    > >
    > > Nothing happens when I select either button.
    > >
    > > What am I missing here?
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >

    >
    >
    Mark Goldin, Jan 30, 2004
    #4
  5. Mark Goldin

    Mark Goldin Guest

    My code was missing
    this.TreeView1.DataBind();

    Works OK now.

    "Mark Goldin" <> wrote in message
    news:#...
    > I have modifed code.
    > Now I am calling same function for both buttons:
    > private void TreeType_CheckedChanged(object sender, System.EventArgs e)
    >
    > {
    >
    > if (this.RadioButton1.Checked == true)
    >
    > this.TreeView1.TreeNodeSrc = "data.xml";
    >
    > if (this.Radiobutton2.Checked == true)
    >
    > this.TreeView1.TreeNodeSrc = "charttreexslt.xml";
    >
    > Response.Write(this.TreeView1.TreeNodeSrc);
    >
    > }
    >
    > Response shows that data souece has been changed properly but the tree

    shows
    > same data all the time.
    >
    > Any idea?
    >
    > "CMA" <> wrote in message
    > news:#...
    > > hi mark again,
    > >
    > > i dont know whether u r using a grouped check boxes. means when i select
    > > 1st, the second one automatically unselect. when i select 2nd, 1st will
    > > unselect.
    > > if it is grouped....
    > > the problem is, always BOTH methods will execute since all two radio

    > buttons
    > > changed the checked property. so the finally executed one will show to

    u.
    > >
    > > solution.
    > > use a radio button list, in the selected index changed.. u can search

    for
    > > the selected item and load the XML depending on the selection.
    > >
    > > else in the RadioButton1_CheckedChanged().. (code in the bottom)
    > > check for the checked property and bind the XML only if checked....
    > >
    > > hope this helps,
    > > CMA
    > >
    > >
    > > "Mark Goldin" <> wrote in message
    > > news:...
    > > > I have a TreeView control and two radiobuttons on my Web form.
    > > > I want to change data source (XML file) of the tree when the user

    clicks
    > > > on buttons.
    > > > Here is Codebehind the buttons:
    > > > private void RadioButton1_CheckedChanged(object sender,

    System.EventArgs
    > > e)
    > > >
    > > > {
    > > >
    > > > TreeView1.TreeNodeSrc = "data.xml";
    > > >
    > > > }
    > > >
    > > > private void Radiobutton2_CheckedChanged(object sender,

    System.EventArgs
    > > e)
    > > >
    > > > {
    > > >
    > > > TreeView1.TreeNodeSrc = "charttreexslt.xml";
    > > >
    > > > }
    > > >
    > > > Autopostback is enabled for both.
    > > >
    > > > Nothing happens when I select either button.
    > > >
    > > > What am I missing here?
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Mark Goldin, Jan 31, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VHltYm93?=
    Replies:
    2
    Views:
    24,427
    =?Utf-8?B?VHltYm93?=
    Jan 10, 2006
  2. Author Tarun Tyagi
    Replies:
    0
    Views:
    694
    Author Tarun Tyagi
    Dec 29, 2004
  3. abargaddon
    Replies:
    0
    Views:
    1,041
    abargaddon
    Jan 17, 2008
  4. Replies:
    0
    Views:
    223
  5. Switch Within A Switch

    , Apr 22, 2006, in forum: Javascript
    Replies:
    7
    Views:
    98
    Lasse Reichstein Nielsen
    Apr 22, 2006
Loading...

Share This Page