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

}

}

相关推荐
大阳光男孩3 小时前
Spring Boot 整合 Debezium 实现 MySQL 增量数据监听(嵌入式版)
spring boot·后端·mysql
皮皮林5513 小时前
ThreadLocal 不香了?ScopedValue才是王道?
后端
X-⃢_⃢-X3 小时前
一、第一阶段:认识 Spring Boot
java·spring boot·后端
前端工作日常4 小时前
我学习到的Java程序的生命周期
java·后端
AskHarries5 小时前
GitHub 登录配置流程
后端
Sinclair7 小时前
安企CMS的安装-常见安装问题排查
运维·后端
Sinclair8 小时前
安企CMS的安装-安装引导与初始化
运维·后端
Sinclair8 小时前
安企CMS的安装-源码编译安装
运维·后端·go
Sinclair8 小时前
安企CMS的安装-同一服务器多站点部署
运维·后端
Sinclair8 小时前
安企CMS的安装-服务器手动部署
运维·后端