简体   繁体   English

RadioButtonList中的项目未触发SelectedIndexChanged

[英]Item in RadioButtonList not firing SelectedIndexChanged

I have a table cell with a RadioButtonList . 我有一个带有RadioButtonList的表格单元格。 When each item is selected, the SelectedIndexChanged event is supposed to fire so the app can populate a related listbox. 选中每个项目后,应该触发SelectedIndexChanged事件,以便该应用可以填充相关的列表框。 The problem is it stopped working. 问题是它停止工作了。 Now if I selected the first entry 'Division', the event never fires. 现在,如果我选择第一个条目“ Division”,则该事件将永远不会触发。 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; [更新]不起作用,是指如果您选择了项目#2,则更新有效。 then if you select Item #1 it doesn't. 那么如果您选择项目#1,则不会。 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;
}

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). 这可能是因为默认的SelectedIndex为0。因此,通过选择第一个单选按钮, SelectedIndex实际上不会更改(因为第一个单选按钮的索引为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. 将单选按钮添加到列表后。

Is it works when you select not first item and after that you select Division item? 如果您不选择第一个项目,然后选择“ Division项目,是否可以使用?

Try to set SelectedIndex to -1 after you add last item (ie before TableCell cellforHierarchyLevel = new TableCell(); line) 在添加最后一项后(即在TableCell cellforHierarchyLevel = new TableCell();行之前),尝试将SelectedIndex设置为-1 TableCell cellforHierarchyLevel = new TableCell();

There was an exception being thrown silently from CreateChildControls(). 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. 修复异常后,该事件已正常处理。

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

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