2012-10-10 98 views
1

我有一個DataList單選按鈕列表內的DataList

<asp:DataList ID="dlfilteritem" runat="server" RepeatDirection="Horizontal" 
    RepeatColumns="3"> 
    <ItemTemplate> 
     <asp:RadioButtonList ID="rblfilteritem" runat="server"> 
     </asp:RadioButtonList> 
    </ItemTemplate> 
</asp:DataList> 

內RadioButtonList控件我如何能趕上單選按鈕的使用的FindControl事件的控制?

+1

???/ –

+0

我有一個下拉列表,我需要得到在下拉列表單選按鈕控制SelectedIndexChanged事件 – ranjenanil

+0

哪裏是DataList控件內部還是外部的下拉??? –

回答

2

您可以隨時使用NamingContainer屬性來獲得您的DataListItem。然後,您可以使用FindControl獲取對您的RadioButtonList的引用。

例如,假設在DataList中有另一個控件回寫爲DropDownList。如果你想從SelectedIndexChanged事件處理程序中找到RadioButtonList

protected void DropDownList1_SelectedIndexChanged(Object sender, EventArgs e) 
{ 
    DropDownList ddl = (DropDownList) sender; 
    DataListItem dli = (DataListItem) ddl.NamingContainer; 
    RadioButtonList rblfilteritem = (RadioButtonList)dli.FindControl("rblfilteritem"); 
} 

如果DropDownList反而是DataList外,你可以通過Items property枚舉所有DataListItems

foreach(DataListItem dli in DataList1.Items) 
{ 
    RadioButtonList rblfilteritem = (RadioButtonList)dli.FindControl("rblfilteritem"); 
} 
+0

DataList1.Items顯示count = 0 – ranjenanil

+0

那麼DataList是否爲空是正確的? –

1

如果你DROPDOWNLIST外datalist那麼你將擁有radiobuttonlist所有值的數組,以便嘗試以下代碼

foreach(DataListItem data in dtdatalist1.Items) 
{ 
RadioButtonList rbl = (RadioButtonList)data.FindControl("rbl"); 
} 
0
protected void dlfilteritem_ItemDataBound(object sender, DataListItemEventArgs e) { 
     if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) 
     {    
      RadioButtonList RBL = ((RadioButtonList)e.Item.FindControl("PopularCity")); 
      RBL.DataSource = dataTable; 
      RBL.DataBind(); 
     } 
    } 
哪個事件你想獲得這種控制
+0

如果您在ItemDataBound函數中找到您的radiobuttonlist – gourishankar