0

私はDataListを使用しています.FooterTemplateにラジオボタンを追加しますIIはそれをチェックしたいですが、常に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

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 に答える