繁体   English   中英

RadioButtonList中的项目未触发SelectedIndexChanged

[英]Item in RadioButtonList not firing SelectedIndexChanged

我有一个带有RadioButtonList的表格单元格。 选中每个项目后,应该触发SelectedIndexChanged事件,以便该应用可以填充相关的列表框。 问题是它停止工作了。 现在,如果我选择第一个条目“ Division”,则该事件将永远不会触发。 我在事件处理程序上设置了一个断点,它被其他条目调用,但不被除法调用。 我相信其他一些代码是否会干扰我,我只是不知道从哪里开始寻找。

[更新]不起作用,是指如果您选择了项目#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;
}

这可能是因为默认的SelectedIndex为0。因此,通过选择第一个单选按钮, SelectedIndex实际上不会更改(因为第一个单选按钮的索引为0)。

您可以通过以下方式以编程方式选择第一个单选按钮:

rbcohortList.SelectedIndex = 0;

将单选按钮添加到列表后。

如果您不选择第一个项目,然后选择“ Division项目,是否可以使用?

在添加最后一项后(即在TableCell cellforHierarchyLevel = new TableCell();行之前),尝试将SelectedIndex设置为-1 TableCell cellforHierarchyLevel = new TableCell();

CreateChildControls()静默引发了一个异常。 这中断了对事件处理程序的调用,这使得似乎未在调用事件处理程序。 修复异常后,该事件已正常处理。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM