I'm going to try to briefly describe the situation because the setup is a bit complicated
I have a RadGrid with popup form insert/edit.
When the popup form appears, the first object is a combobox that contains the Report ID.
The ItemDataBound event for the grid populates the popup form with the correct Report Options by building the controls and adding them to a Panel container. The Report Options are determined by the combobox that contains the Report ID
For example...if the Report ID is 1, the ItemDataBound event generates 2 comboboxes for Report Date and Report Format. Report Date has 4 options and Report Format has 2 options.
Now...the combobox for the Report ID is set to autopostback and there is a OnSelectedIndexChanged event that reruns the code that creates the Report Option controls.
For example...if I change the combobox so that the Report ID is 2, the ItemDataBound event only generates 1 combobox for Report Format which is supposed to only have 2 options.
Here's where the problem occurs. All of this works perfectly, except that when I select Report ID 2, the combobox for Report Format has 4 options in it...the last 2 are completely blank.
It seems that for some reason it's remembering that the first combobox when Report ID was selected had 4 options and even though it's changing the combobox to have the right values, it still thinks there is supposed to be 4 options when in fact there are only 2.
I tried doing a combo.Items.Clear() before building the combobox, but that didn't seem to work. I also tried clearing out the controls on the Panel and that didn't work either. You can also see from the code below that each combobox is created with a unique ID based on the ID of the Option. The Report Date combobox is generated as dd_1 while the Report Format combobox is generated as dd_8.
I guess I'm looking for a way to make sure the ComboBox has the correct number of options so that the user cannot select "blank" items.
I don't know how much help this code is going to be, but here is how I'm creating the controls
Any suggestions you can provide are greatly appreciated...thanks.
I have a RadGrid with popup form insert/edit.
When the popup form appears, the first object is a combobox that contains the Report ID.
The ItemDataBound event for the grid populates the popup form with the correct Report Options by building the controls and adding them to a Panel container. The Report Options are determined by the combobox that contains the Report ID
For example...if the Report ID is 1, the ItemDataBound event generates 2 comboboxes for Report Date and Report Format. Report Date has 4 options and Report Format has 2 options.
Now...the combobox for the Report ID is set to autopostback and there is a OnSelectedIndexChanged event that reruns the code that creates the Report Option controls.
For example...if I change the combobox so that the Report ID is 2, the ItemDataBound event only generates 1 combobox for Report Format which is supposed to only have 2 options.
Here's where the problem occurs. All of this works perfectly, except that when I select Report ID 2, the combobox for Report Format has 4 options in it...the last 2 are completely blank.
It seems that for some reason it's remembering that the first combobox when Report ID was selected had 4 options and even though it's changing the combobox to have the right values, it still thinks there is supposed to be 4 options when in fact there are only 2.
I tried doing a combo.Items.Clear() before building the combobox, but that didn't seem to work. I also tried clearing out the controls on the Panel and that didn't work either. You can also see from the code below that each combobox is created with a unique ID based on the ID of the Option. The Report Date combobox is generated as dd_1 while the Report Format combobox is generated as dd_8.
I guess I'm looking for a way to make sure the ComboBox has the correct number of options so that the user cannot select "blank" items.
I don't know how much help this code is going to be, but here is how I'm creating the controls
protected
void
BuildOptions(GridEditFormItem editFormItem)
{
RadComboBox dd_RptID = (RadComboBox)editFormItem.FindControl(
"dd_RptID"
);
EISDataContext db =
new
EISDataContext();
// get the unique report options for the current selected report so we can render the correct controls
var q_options = (from options
in
db.tReportConfigs
where options.RptID == dd_RptID.SelectedItem.Value
select options.OptID).Distinct();
foreach
(var option
in
q_options)
{
string
optionType = (from options
in
db.tReportOptions
where options.OptID == option
select options.OptTyp).FirstOrDefault();
string
optionName = (from options
in
db.tReportOptions
where options.OptID == option
select options.OptNm).FirstOrDefault();
// get the option values for this option
var q_optionValues = from optionvalues
in
db.tReportConfigs
where optionvalues.RptID == dd_RptID.SelectedItem.Value && optionvalues.OptID == option
select optionvalues;
// create a div for the option control and populate it with the correct control
Panel panelContent =
new
Panel();
panelContent.Attributes.Add(
"class"
,
"popupcontent"
);
if
(optionType ==
"ComboBox"
)
{
RadComboBox combo =
new
RadComboBox();
combo.ID =
"dd_"
+ option.ToString();
foreach
(var optionValue
in
q_optionValues)
{
combo.Items.Add(
new
RadComboBoxItem(optionValue.tReportOptionValue.OptNm, optionValue.tReportOptionValue.OptVal));
}
panelContent.Controls.Add(combo);
}
// create a div for the option title and populate it with the option name
Panel panelTitle =
new
Panel();
panelTitle.Attributes.Add(
"class"
,
"popuptitle"
);
Label pnlLabel =
new
Label();
pnlLabel.Text = optionName;
panelTitle.Controls.Add(pnlLabel);
// create a div for the clear control
Panel panelClear =
new
Panel();
panelClear.Attributes.Add(
"class"
,
"clear"
);
editFormItem.FindControl(
"divOptions"
).Controls.Add(panelTitle);
editFormItem.FindControl(
"divOptions"
).Controls.Add(panelContent);
editFormItem.FindControl(
"divOptions"
).Controls.Add(panelClear);
}
}
Any suggestions you can provide are greatly appreciated...thanks.