Switch data source of TreeView

M

Mark Goldin

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?
 
C

CMA

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
 
M

Mark Goldin

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

Mark Goldin

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top