如何在C#上接收单选按钮组的值

时间:2018-11-27 19:22:04

标签: c# html asp.net

我在html中有代码:

<form runat="server"> 
       <table>
           <tr>
               <td>
                   From Date:
               </td>
               <td>
                   <input type="text" runat="server" id="txtDate" placeholder="YYYY-MM-DD"/>
               </td>
           </tr>
           <tr>
               <td>
                   Show Data:
               </td>
               <td>
                   <input type="radio" id="rbShowDataYes" name="chShowData" value="1" checked="checked"> Yes
                   <input type="radio" id="rbShowDataNo" name="chShowData" value="0"> No
               </td>
           </tr>
...
</form>

在c#中,当我尝试到达txtDate.Value时,它正在运行,但是rbShowDataYes.Checked无效,表示rbShowDataYes不在当前上下文中。我的错误在哪里?

1 个答案:

答案 0 :(得分:0)

string value=chShowData.SelectedItem.Value.ToString();


bool isChecked = radioButton1.Checked;
if(isChecked )
  value=radioButton1.Text;
else
  value=radioButton2.Text;