如何将单选按钮值与asp.net中的文本框值进行比较

我有四个单选按钮和一个文本框..我必须检查所选单选按钮值是否等于文本框值..任何人PLZ帮助我     
已邀请:
if(radioButtonList.SelectedValue == textBox1.Text.Trim())
{
   //your code goes here
}
    
textBox不包含Value属性。
if (!string.IsNullOrEmpty(RadioButtonList1.SelectedValue) &&
                RadioButtonList1.SelectedValue.Equals(TextBox1.Text, StringComparison.Ordinal))
    {
        //your code goes here
    }
    
好吧。你没有说明你想要做什么比较,即ClientSide或ServerSide。如果你想要服务器端,你可以更喜欢早期发布的答案,否则客户端使用Jquery尝试这个。
<div>
    <input type='radio' name='rd' value='A'>
    <input type='radio' name='rd' value='B'>
    <input type='radio' name='rd' value='C'>
    <br />
    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</div>

<script type="text/javascript" >
    $(document).ready(function(){
    $("input:radio[name='rd']").click(function(){
        if($(this).is(":checked"))
        {
            if($.trim($(this).val()) == $.trim($("#txtName").val()))
                alert("Yeah!I got matched value.");
            else
                alert("Oops!Not matched.");
        }
    });

    });
</script>
点击此链接: DEMO     

要回复问题请先登录注册