ASP.Net单选按钮不会改变状态

时间:2013-11-21 16:47:14

标签: asp.net radio-button

在asp.net表单中,我有一组单选按钮,都具有相同的groupID。在同一表格上,我有一个重置按钮。在重置按钮的代码中,我设置了我想要检查的默认单选按钮,如rb.Checked = true。问题是单选按钮的检查状态不会改变。为什么不呢?

ASP.Net:

 <asp:Table ID="tblFullText" runat="server" Width="95%" HorizontalAlign="Center" Font-Size="10pt" CellSpacing="0"
 BorderWidth="1px" CellPadding="0" GridLines="Both" BorderStyle="Solid" BorderColor="#c0c0c0">
  <asp:TableRow HorizontalAlign="Center" BackColor="LightSteelBlue" Font-Bold="True">
    <asp:TableCell ColumnSpan="3" Font-Bold="true" Text="FULL TEXT SEARCH PARAMETERS"></asp:TableCell>
  </asp:TableRow>
  <asp:TableRow HorizontalAlign="Center" BackColor="LightSteelBlue" Font-Bold="True">
  <asp:TableCell Width="50%" Text="Search Criteria"></asp:TableCell>
  <asp:TableCell Width="17%" Text="Query Operator"></asp:TableCell>
  <asp:TableCell Width="33%" Text="Query Expression Type"></asp:TableCell>
  </asp:TableRow>
  <asp:TableRow>
  <asp:TableCell Width="50%" HorizontalAlign="Center"><asp:textbox id="tbFullTextSearchCriteria" runat="server" Width="98%"></asp:textbox></asp:TableCell>
  <asp:TableCell Width="17%" HorizontalAlign="Center">
    <asp:RadioButton runat="server" GroupName="QueryOp" ID="rbQueryOpAnd" Text="<b>AND</b>" />&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:RadioButton runat="server" GroupName="QueryOp" ID="rbQueryOpOR" Text="<b>OR</b>" />
  </asp:TableCell>
  <asp:TableCell Width="33%" HorizontalAlign="Center">
    <asp:RadioButton runat="server" GroupName="QueryExpType" ID="rbQueryExpTypeAll" Text="<b>All Words</b>" />&nbsp;&nbsp;
    <asp:RadioButton runat="server" GroupName="QueryExpType" ID="rbQueryExpTypeAny" Text="<b>Any Word</b>" />&nbsp;&nbsp;
    <asp:RadioButton runat="server" GroupName="QueryExpType" ID="rbQueryExpTypeExact" Text="<b>Exact Phrase</b>" />&nbsp;&nbsp;
    <asp:RadioButton runat="server" GroupName="QueryExpType" ID="rbQueryExpTypeExpr" Text="<b>Expression</b>" />
  </asp:TableCell>
  </asp:TableRow>
</asp:Table>

代码背后:

  Protected Sub btnClearFields_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnClearFields.Click

    rbQueryOpAnd.Checked = True

  End Sub

1 个答案:

答案 0 :(得分:1)

您还需要将同一组中的其他RadioButton设置为false。

Protected Sub btnClearFields_Click(ByVal sender As Object, ByVal e As EventArgs) 
   Handles btnClearFields.Click

    rbQueryOpAnd.Checked = True
    rbQueryOpOR.Checked = False

End Sub

如果您不想将其他RadioButton设置为false,则需要使用RadioButtonList