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

}

}

相关推荐
你的人类朋友12 小时前
说说签名与验签
后端
databook12 小时前
Manim实现脉冲闪烁特效
后端·python·动效
canonical_entropy16 小时前
AI时代,我们还需要低代码吗?—— 一场关于模型、演化与软件未来的深度问答
后端·低代码·aigc
颜如玉16 小时前
HikariCP:Dead code elimination优化
后端·性能优化·源码
考虑考虑17 小时前
Jpa使用union all
java·spring boot·后端
bobz96518 小时前
virtio vs vfio
后端
Rexi18 小时前
“Controller→Service→DAO”三层架构
后端
bobz96519 小时前
计算虚拟化的设计
后端
深圳蔓延科技19 小时前
Kafka的高性能之路
后端·kafka
Barcke19 小时前
深入浅出 Spring WebFlux:从核心原理到深度实战
后端