0

我正在使用 DataList。在我的 FooterTemplate 中,我添加了一个单选按钮,我想检查它。但它总是返回 false。

这是我的代码

<asp:DataList ID="dlDelivery" OnItemDataBound="dlDelivery_DataBound"  RepeatColumns="1"  RepeatDirection="Vertical" Width="300" runat="server">
    <ItemTemplate>
        <asp:RadioButton ID="rdoDel" GroupName="aaa" OnCheckedChanged="rdoOther_Changed" AutoPostBack="true" runat="server" />
        <asp:Label ID="lblDel1"  Text='<%# Eval("Street") %>' runat="server" /><br />
        <asp:Label ID="lblDel2"  Text='<%# Eval("Suburb") %>' runat="server" /> 

        <span class="clear" />
    </ItemTemplate>
    <FooterTemplate>
    <asp:RadioButton ID="rdoOther" Text="Other" OnCheckedChanged="rdoOther_Changed" AutoPostBack="true" GroupName="aaa" runat="server" />
    a
    <br class="clear" />

    </FooterTemplate>
    </asp:DataList>

我像这样检查 rdoOther 检查

 RadioButton rdoOther = (RadioButton)dlDelivery.Controls[dlDelivery.Controls.Count - 1].Controls[0].FindControl("rdoOther"); 

            if (rdoOther.Checked = true ) // this always fales
{
}

如何解决?

4

2 回答 2

1

尝试这个

        foreach (DataListItem item in dlDelivery.Items)
        {
            if (item.ItemType == ListItemType.Footer)
            {
                RadioButton rdoOther = (RadioButton)item.FindControl("rdoOther");

            }
        }
于 2013-09-02T05:25:43.477 回答
0

只需在 e.Item 中搜索单选按钮:

protected void dlDelivery_DataBound(object sender, DataListItemEventArgs e)
{
    RadioButton rdoOther = e.Item.FindControl("rdoOther") as RadioButton;

    //rdoOther  will be null if ListItemType is not footer.
    if (rdoOther !=null && rdoOther.Checked)
    {
        // Do your tasks
    }
}
于 2013-09-02T06:12:57.203 回答