Hi, I have a very annoying problem with my comboboxes that occurs not everytime but i would say ~5% of the time, testing on IE8 and FF 14.0.1. My scenario (using Q2 2012):
Im having 2 related comboboxes in a RadAjaxPanel which are filled once from a database. Each combobox filters each other since the first one contains the parents of the second. Im using server-side coding to do the filtering (by using item visibility, based on Parent (Attribute) property).
95%, everthing works like it should but i noticed that sometimes the filtering does not occur (selecting an element in the first combobox doesnt filter the second one at all...it visible items stays like there were). I though first that the postback was not occuring on those times but after investigation, it is (OnSelectedIndexChanged gets called and item visibility is set correctly for all items). It's just the displaying that dont get refreshed somehow. The only way I can do something is selecting something else in the first combobox and reselecting the one i really wanted (to force an index change)...then it filters.
I initially had AutoPostBack=True on both comboboxes and tried to put them to false and handle it on client-side (OnClientSelectedIndexChanged), like someone did on a forums. Problem still occuring ...but seems like less often so i kept it like that.
Here's a trimmed down version of my code:
aspx
js
cs
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
RadComboBoxItem item =
null
;
item =
new
RadComboBoxItem();
item.Value =
"1"
;
item.Text =
"Canada"
;
RadComboBox1.Items.Add(item);
item =
new
RadComboBoxItem();
item.Value =
"2"
;
item.Text =
"USA"
;
RadComboBox1.Items.Add(item);
item =
new
RadComboBoxItem();
item.Value =
"3"
;
item.Text =
"BC"
;
RadComboBox2.Items.Add(item);
item =
new
RadComboBoxItem();
item.Value =
"4"
;
item.Text =
"NB"
;
RadComboBox2.Items.Add(item);
item =
new
RadComboBoxItem();
item.Value =
"5"
;
item.Text =
"ON"
;
RadComboBox2.Items.Add(item);
item =
new
RadComboBoxItem();
item.Value =
"6"
;
item.Text =
"CAL"
;
RadComboBox2.Items.Add(item);
item =
new
RadComboBoxItem();
item.Value =
"7"
;
item.Text =
"FLA"
;
RadComboBox2.Items.Add(item);
item =
new
RadComboBoxItem();
item.Value =
"8"
;
item.Text =
"NY"
;
RadComboBox2.Items.Add(item);
RadComboBox1.Text =
""
;
RadComboBox1.ClearSelection();
RadComboBox1.Visible =
true
;
RadComboBox2.Text =
""
;
RadComboBox2.ClearSelection();
RadComboBox2.Visible =
true
;
}
}
protected
void
RadComboBox1_OnSelectedIndexChanged(
object
sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
FilterNext(
ref
RadComboBox1,
ref
RadComboBox2);
}
private
void
FilterNext(
ref
RadComboBox cbCurrent,
ref
RadComboBox cbNext)
{
if
(cbCurrent.Text ==
"Canada"
)
{
for
(
int
i = 0; i <= cbNext.Items.Count - 1; i++)
{
if
(cbNext.Items[i].Text ==
"BC"
|| cbNext.Items[i].Text ==
"NB"
|| cbNext.Items[i].Text ==
"ON"
)
{
cbNext.Items[i].Visible =
true
;
//WriteLog("true " + cbNext.Items[i].Text);
}
else
{
cbNext.Items[i].Visible =
false
;
//WriteLog("false " + cbNext.Items[i].Text);
}
}
}
if
(cbCurrent.Text ==
"USA"
)
{
for
(
int
i = 0; i <= cbNext.Items.Count - 1; i++)
{
if
(cbNext.Items[i].Text ==
"CAL"
|| cbNext.Items[i].Text ==
"FLA"
|| cbNext.Items[i].Text ==
"NY"
)
{
cbNext.Items[i].Visible =
true
;
//WriteLog("true " + cbNext.Items[i].Text);
}
else
{
cbNext.Items[i].Visible =
false
;
//WriteLog("false " + cbNext.Items[i].Text);
}
}
}
cbNext.DataBind();
}
For those who want to test it out...please spend time on selection changing.. I usually need to spend like 2-3min to making it fail.
Please help and TIA