C
charles.boyung
I am trying to use the treeview to display a hierarchy of categories
depending on the top level category chosen from a radiobuttonlist.
However, I am running into a problem where the treeview does not work
correctly (or at least, as expected). When I select a radio button
the first time, it works fine. However, if I select a different radio
button, the tree view does not change to reflect that change - the
original results are still shown. It seems like ASP.Net is caching
that control no matter what I do for as long as the page is alive.
Here is a code sample that can reproduce this issue:
<asp:RadioButtonList runat="Server" ID="rblTest" AutoPostBack="True"
OnSelectedIndexChanged="rblTest_SelectedIndexChanged">
<asp:ListItem Text="Test0" Value="0" />
<asp:ListItem Text="Test1" Value="1" />
</asp:RadioButtonList>
<asp:TreeView runat="server" ID="tvwTest"
ShowCheckBoxes="All" ShowExpandCollapse="False">
<DataBindings>
<asp:TreeNodeBinding DataMember="Category" TextField="Description"
ValueField="ID" />
</DataBindings>
</asp:TreeView>
protected void rblTest_SelectedIndexChanged(object sender, EventArgs
e)
{
XmlDataSource data = new XmlDataSource();
if (rblTest.SelectedIndex == 0)
{
data.Data = "<Category ID=\"520\" Description=\"Desserts\"><Category
ID=\"709\" Description=\"All Others\" /><Category ID=\"692\"
Description=\"Bars\" /></Category>";
}
else
{
data.Data = "<Category ID=\"520\" Description=\"Desserts2\"><Category
ID=\"709\" Description=\"All Others2\" /><Category ID=\"692\"
Description=\"Bars2\" /></Category>";
}
this.tvwTest.DataSource = data;
this.tvwTest.DataBind();
}
I would greatly appreciate any help with this that anyone can provide.
Thanks,
Charles Boyung
depending on the top level category chosen from a radiobuttonlist.
However, I am running into a problem where the treeview does not work
correctly (or at least, as expected). When I select a radio button
the first time, it works fine. However, if I select a different radio
button, the tree view does not change to reflect that change - the
original results are still shown. It seems like ASP.Net is caching
that control no matter what I do for as long as the page is alive.
Here is a code sample that can reproduce this issue:
<asp:RadioButtonList runat="Server" ID="rblTest" AutoPostBack="True"
OnSelectedIndexChanged="rblTest_SelectedIndexChanged">
<asp:ListItem Text="Test0" Value="0" />
<asp:ListItem Text="Test1" Value="1" />
</asp:RadioButtonList>
<asp:TreeView runat="server" ID="tvwTest"
ShowCheckBoxes="All" ShowExpandCollapse="False">
<DataBindings>
<asp:TreeNodeBinding DataMember="Category" TextField="Description"
ValueField="ID" />
</DataBindings>
</asp:TreeView>
protected void rblTest_SelectedIndexChanged(object sender, EventArgs
e)
{
XmlDataSource data = new XmlDataSource();
if (rblTest.SelectedIndex == 0)
{
data.Data = "<Category ID=\"520\" Description=\"Desserts\"><Category
ID=\"709\" Description=\"All Others\" /><Category ID=\"692\"
Description=\"Bars\" /></Category>";
}
else
{
data.Data = "<Category ID=\"520\" Description=\"Desserts2\"><Category
ID=\"709\" Description=\"All Others2\" /><Category ID=\"692\"
Description=\"Bars2\" /></Category>";
}
this.tvwTest.DataSource = data;
this.tvwTest.DataBind();
}
I would greatly appreciate any help with this that anyone can provide.
Thanks,
Charles Boyung