簡體   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