如何在不使用asp.net中的按钮的情况下在文本框中显示单选按钮值? [英] How to display radio button values in a textbox without using of button in asp.net ?

查看:73
本文介绍了如何在不使用asp.net中的按钮的情况下在文本框中显示单选按钮值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!!我是asp.net的新手并且有疑问。我想知道如何在asp.net的文本框中显示单选按钮值。

例如:我有两个单选按钮,其值为男性和女性。我的疑问是,每当我点击男性单选按钮时,另一个文本框将显示男性。

在此先感谢

Hello!! I"m new to asp.net and have a doubt. I want to know how to display radio button values in a textbox in asp.net.
Ex: I have two radio buttons and there values are "Male" and "Female". My query is that whenever i"ll click on "Male" radio button another textBox will show "Male".
Thanks In Advance

推荐答案

好的,在radiobutton的checkchanged事件上,将文本框的text属性设置为radiobutton的选定项目值。



以下是我要做的,将其添加到您的html表单:



Ok, so on the checkchanged event of the radiobutton, set the text attribute of the textbox to the selected item value of the radiobutton.

Here is what I would do, add this to your html form:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:RadioButton ID="RadioButton1" runat="server" GroupName="choice" 

             oncheckedchanged="RadioButton1_CheckedChanged" Text="Male" AutoPostBack="True"/>
        <asp:RadioButton ID="RadioButton2" runat="server" GroupName="choice" 

             Text="Female" AutoPostBack="True" 

             oncheckedchanged="RadioButton2_CheckedChanged"/>;





并将其添加到您的代码隐藏中:





and add this to your code-behind:

protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (RadioButton1.Checked)
            {
                TextBox1.Text = "Male";
            }
        }
        protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (RadioButton2.Checked)
            {
                TextBox1.Text = "Female";
            }
        }


首先更改单选按钮的属性AutoPostBack = true;

接下来是解决方案2中所述。
First change both radio button's properties of AutoPostBack = true;
Next is as described in Solution 2.


您好,



首先制作RadioButton autopostback为true ....

然后使用如下....



在特定的单选按钮事件处理程序下使用此... 。



Hi,

First make RadioButton autopostback to true....
Then use as follows....

Under particular radio button event handler use this....

protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (RadioButton1.Checked)

                TextBox1.Text = RadioButton1.Text;
        }


这篇关于如何在不使用asp.net中的按钮的情况下在文本框中显示单选按钮值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆