我无法从datalist的单选按钮asp.net获取已检查的属性值

时间:2013-09-20 18:46:45

标签: c# asp.net radio-button datalist

我可以获取此单选按钮的文本和其他属性,但是对于已检查的属性,它将始终返回false

<asp:DataList ID="DataList1" runat="server" Width="904px">
    <ItemTemplate>
        <table style="width: 100%;" border="1">            
            <tr>
                        <td>
                            <asp:RadioButton ID="option1" runat="server" GroupName="Options" Text="A" />

                            <%# DataBinder.GetPropertyValue(Container.DataItem, "op1") %>
                        </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:DataList>

C#代码:

protected void Button1_Click(object sender, EventArgs e)
{
    int counter = 0;
    foreach (DataListItem item in DataList1.Items)
    {           
        RadioButton rb1 = (RadioButton)item.FindControl("option1");
        if (rb1.Checked)
        {
            counter++;
        }
    }
    Response.Write(counter);
}

0 个答案:

没有答案