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 = "测试";

}

}

相关推荐
落枫5910 分钟前
如何快速搭建一个JAVA持续交付环境
后端·github
用户83562907805110 分钟前
如何将 Python 列表高效导出为 Excel 文件
后端·python
止水编程 water_proof15 分钟前
SpringBoot快速上手
java·spring boot·后端
li.wz20 分钟前
ShardingSphere 与 PolarDB-X 选型对比
java·后端·微服务
得物技术1 小时前
RocketMQ高性能揭秘:承载万亿级流量的架构奥秘|得物技术
后端·rocketmq
普通码农1 小时前
PowerShell 神操作:输入「p」直接当「pnpm」用,敲命令速度翻倍!
前端·后端·程序员
绝无仅有2 小时前
Git 操作偏门指南:常用和隐藏命令与问题解决
后端·面试·github
绝无仅有2 小时前
通过程序对接地图api展示旅游数据列表
后端·面试·github
老马95272 小时前
MyBatis-Plus 动态表名的正确打开方式
后端·mybatis
Java水解3 小时前
springboot: Spring Boot 启动流程详解
spring boot·后端