1

我在数据列表中有一个单选按钮列表控件

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

如何在使用 findcontrol 的事件中捕获单选按钮的控制?

4

3 回答 3

2

您始终可以使用该NamingContainer属性来获取您的DataListItem. 然后您可以使用FindControl来获取对您的RadioButtonList.

例如,假设在DataList回传的控件中有另一个控件,如DropDownList. 如果要在事件处理程序中查找RadioButtonListfrom :SelectedIndexChanged

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

如果DropDownList相反,您可以通过propertyDataList枚举所有内容:DataListItemsItems

foreach(DataListItem dli in DataList1.Items)
{
     RadioButtonList rblfilteritem = (RadioButtonList)dli.FindControl("rblfilteritem");
}
于 2012-10-10T07:49:51.497 回答
1

如果您在数据列表之外有下拉列表,那么您将拥有单选按钮列表的所有值的数组,因此请尝试以下代码

foreach(DataListItem data in dtdatalist1.Items)
{
RadioButtonList rbl = (RadioButtonList)data.FindControl("rbl");
}
于 2012-10-10T07:58:23.197 回答
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();
        }
    }
于 2014-01-08T11:18:04.847 回答