2010-08-10 49 views
0

我有一个表单元格,其中有RadioButtonList。当选择每个项目时,SelectedIndexChanged事件应该触发,以便应用程序可以填充相关列表框。问题是它停止工作。现在,如果我选择了第一项“分区”,该事件从不会发生。我在事件处理程序中放置了一个断点,并为其他条目调用它,但不是为Division调用。如果其他代码干扰我会相信,我只是不知道从哪里开始寻找。RadioButtonList中的项目未触发SelectedIndexChanged

[更新] 由于不工作,我的意思是如果您选择项目#2,则更新有效;那么如果你选择项目#1它不。如果我更改了“分部”项目出现在列表中的位置,它仍然存在问题。页面加载循环中是否有可能会中止事件处理链的内容?

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; 
} 

回答

0

有一个例外,正在从默默的CreateChildControls抛出()。这中断了对事件处理程序的调用,这看起来像事件处理程序没有被调用。当我修复异常时,事件处理正常。

0

它可能是因为默认SelectedIndex是0,所以选择第一个单选按钮,在SelectedIndex实际上并没有改变(因为第一个单选按钮将索引0)。

您可以只用做选择第一个单选按钮编程:

rbcohortList.SelectedIndex = 0; 

您已经添加单选按钮列表后。

+0

这可以通过将除第一个以外的ListItem设置为选定值来证明。然后选择列表中的第一个项目将触发更改事件。虽然如果页面第一次加载时没有选择单选按钮,我不明白为什么更改事件不会触发...... – Jeremy 2010-08-10 19:01:09

+0

对,没有提供默认SelectedIndex的事实意味着当第一个选项是选择,事件不会因为索引确实,没有改变。 – SwDevMan81 2010-08-10 19:04:47

0

它是否适用于您选择不是第一个项目,然后选择Division项目?

尝试设置SelectedIndex-1添加最后一个项目之后(即前TableCell cellforHierarchyLevel = new TableCell();线)

相关问题