ASP.NET单选框与多选框值获取

【多选获取值】:
<div>
    <asp:Label ID="Label1" runat="server" Text="ListBox多选"></asp:Label><br />
    <asp:ListBox ID="ListBox1" runat="server" Height="103px" Width="212px" SelectionMode="Multiple">
        <asp:ListItem>Java</asp:ListItem>
        <asp:ListItem>HTML</asp:ListItem>
        <asp:ListItem Value="Web">Web前端开发</asp:ListItem>
    </asp:ListBox>
    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>

----------------------------------------------------------------------------------------------------

public partial class Default2 : System.Web.UI.Page
{
    String i;//1.定义变量
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach(ListItem lst in ListBox1.Items)//2.循环取出(ListBox1为多选控件的ID)
        {
            if (lst.Selected)
            {
                i += lst.Text;
            }
        }
        Response.Write(i);//在网页上输出i变量的内容
    }
}

----------------------------------------------------------------------------------------------------

【单选获取值】:
string gender = rblxb.SelectedValue;//将列表控件id为rblxb的Value值赋给字符串变量gender

-----------------------------------------------------------------------------------------------------

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
    String jg = RadioButtonList1.SelectedValue.ToString();
    if (jg == "wqndyd")
    {
        s1.Text = "测试";
    }
}

相关推荐

  1. ASP.NET获取

    2024-03-27 08:08:02       37 阅读
  2. WPF之RadioButton和checkbox

    2024-03-27 08:08:02       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-27 08:08:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-27 08:08:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-27 08:08:02       87 阅读
  4. Python语言-面向对象

    2024-03-27 08:08:02       96 阅读

热门阅读

  1. C#学习笔记

    2024-03-27 08:08:02       41 阅读
  2. Redis的持久化机制是怎样的?

    2024-03-27 08:08:02       43 阅读
  3. Day58| 739 每日温度 496 下一个更大元素 I

    2024-03-27 08:08:02       39 阅读
  4. Django——Ajax请求

    2024-03-27 08:08:02       38 阅读
  5. 2960. 统计已测试设备

    2024-03-27 08:08:02       41 阅读
  6. 5.92 BCC工具之bitesize.py解读

    2024-03-27 08:08:02       36 阅读