All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
asp.net,后台代码如何遍历checkbox_[Asp.Net教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/1/30 1:17:27 Browse times: 361 Comment times: 0

asp.net,后台代码如何遍历checkbox_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

asp.net 后台代码如何遍历checkbox_[Asp.Net教程] aspx设计页面
//这个是检测按钮,检测下面的checkbox是否被选中。选中时打印其值

第一种设计:(.net 自带的)




第二种设计:(html 自带的,但含有runnat="server")


第三种设计:(html 自带的)


aspx.cs文件 (将按照对应的上面的三种设计模式去写后台代码。其他的单选按钮也类似。)
protected void Button1_Click(object sender, EventArgs e)
{
//这个是上面第一种模式
foreach (Control ct in form1.Controls)
{
if (ct.GetType().ToString().Equals("System.Web.UI.WebControls.CheckBox"))
{
CheckBox cb = (CheckBox)ct;
if (cb.Checked == true)
{
Response.Write(cb.Text);
}
}
}
//这个是上面第二种模式。(直接用request取值,会报错的。不信试试)
foreach (Control ct in form1.Controls)
{
if (ct.GetType().ToString().Equals("System.Web.UI.HtmlControls.HtmlInputCheckBox"))
{
HtmlInputCheckBox cb = (HtmlInputCheckBox)ct;
if (cb.Checked == true)
{
Response.Write(cb.Value);
}
}
}
//这个是上面第三种模式。(没有runnat="server",用request取值 最简单)
Response.Write(Request["aa"].ToString());
}




There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.