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

}

}

相关推荐
用户298698530147 分钟前
Java 实战:精准操控 Word 文档中的内容控件
java·后端
李白的天不白8 分钟前
spring boot + vue3项目部署须知
java·spring boot·后端
传说之后16 分钟前
Go语言入门:从零到Hello World
后端·编程语言
ingcc17 分钟前
gorm时间处理
后端
ingcc19 分钟前
Spring事务简介【重点】
后端
ingcc21 分钟前
SpringAOP简介和作用
后端
椒盐土豆22 分钟前
Spring的事务捕捉器一看就懂!
后端
小谢小哥23 分钟前
64-依赖冲突解决详解
java·后端·架构
阿杰AJie26 分钟前
ExcelUtils样式相关工具
java·后端
用户6081865279028 分钟前
阿里云OSS工具类完整设计与实现:基于.NET的静态单例模式实践
后端