views:

144

answers:

3

I have a table cell with a RadioButtonList. When each item is selected, the SelectedIndexChanged event is supposed to fire so the app can populate a related listbox. The problem is it stopped working. Now if I selected the first entry 'Division', the event never fires. I put a break-point on the event handler and it gets called for the other entries but not for Division. I'd believe it if some other code is interfering, I just don't know where to start looking.

[update] By not working, I mean if you selected Item #2, the update works; then if you select Item #1 it doesn't. If I change where the 'Division' item appears in the list, it still has the problem. Is there something in the page load cycle that could be aborting the event handling chain?

private TableCell foo()    
{
hierarchyLevel = new RadioButtonList();

ListItem DivisionItem = new ListItem();
DivisionItem.Text = "Division";
DivisionItem.Value = "afe_dvsn";        
hierarchyLevel.Items.Add(DivisionItem);

ListItem DistrictItem = new ListItem();
DistrictItem.Text = "District";
DistrictItem.Value = "afe_dist";
hierarchyLevel.Items.Add(DistrictItem);

ListItem AreaItem = new ListItem();
AreaItem.Text = "Area";
AreaItem.Value = "afe_supt";
hierarchyLevel.Items.Add(AreaItem);

ListItem ForemanItem = new ListItem();
ForemanItem.Text = "Foreman";
ForemanItem.Value = "afe_frmn";
hierarchyLevel.Items.Add(ForemanItem);

ListItem AfeCodeItem = new ListItem();
AfeCodeItem.Text = "AFE Code";
AfeCodeItem.Value = "afe_code";
hierarchyLevel.Items.Add(AfeCodeItem);

ListItem PropertyItem = new ListItem();
PropertyItem.Text = "Property";
PropertyItem.Value = "prop_sub";
hierarchyLevel.Items.Add(PropertyItem);

TableCell cellforHierarchyLevel = new TableCell();
cellforHierarchyLevel.ID = "hierarchyLevel";
cellforHierarchyLevel.Controls.Add(hierarchyLevel);

hierarchyLevel.EnableViewState = true;

hierarchyLevel.AutoPostBack = true;

hierarchyLevel.SelectedIndexChanged += new EventHandler(hierarchyLevel_SelectedIndexChanged);

return cellforHierarchyLevel;
}
A: 

Its probably because the default SelectedIndex is 0. So by selecting the first radio button, the SelectedIndex does not actually change (since the first radio button would be index 0).

You can just select the first radio button programmatically by doing:

rbcohortList.SelectedIndex = 0;

after you have added the radio buttons to the list.

SwDevMan81
This could be proven by setting one of the ListItems other than the first one to be the selected value. Then selecting the first item in the list would fire the change event. Although if the radio button isn't selected when the page first loads, i don't see why the change event wouldn't fire anyway...
Jeremy
Right, the fact that no default SelectedIndex is provided means that when the first option is selected, the event wont fire because the index indeed, has not changed.
SwDevMan81
A: 

Is it works when you select not first item and after that you select Division item?

Try to set SelectedIndex to -1 after you add last item (i.e. before TableCell cellforHierarchyLevel = new TableCell(); line)

Pavel Morshenyuk
A: 

There was an exception being thrown silently from CreateChildControls(). This interrupted the call to the event handler which made it seem like the event handler wasn't being called. When I fixed the exception, the event was handled normally.

Kelly French