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 小时前
GO01-Go 语言与主流编程语言深度对比
开发语言·人工智能·后端·微服务·云原生·golang·go
世界哪有真情2 小时前
拿人类意识卡 AI?等于用 bug 验收正式产品
前端·人工智能·后端
Csvn4 小时前
Day 3:LIKE 与模式匹配 — 让查询学会"模糊搜索"
后端·sql
Hazenix6 小时前
Go 指南:一篇文章速通 Golang
开发语言·后端·golang
灯澜忆梦6 小时前
GO_复合类型---指针
开发语言·后端·golang
IT_陈寒6 小时前
SpringBoot自动装配坑了我一天,原来问题出在这
前端·人工智能·后端
星栈6 小时前
深度复盘:比 EventLoop 更隐蔽!Node 微任务堆积引发的线上接口雪崩事故
后端·node.js
名字还没想好☜7 小时前
Go slice 的 append 陷阱:共享底层数组导致的数据串改
开发语言·后端·golang·go·slice
诸神缄默不语7 小时前
FastAPI后端配置CORS中间件支持浏览器跨域访问
后端·fastapi
Fanta丶7 小时前
14.Activiti7 网关 排他网关ExclusiveGateway、并行网关ParallelGateway
后端