简单教程ASP.NET获取CheckBoxList多选的值源代码
下面是ASP.NET程序中常用的获取CheckBoxList多选项值的例子,很简单,技术含量不高,对于初学者可以学习下,下面开始吧。 第1、前面ASPX页面源码: .ASPX Code [http://www.xueit.com] % @ Page Lan
下面是ASP.NET程序中常用的获取CheckBoxList多选项值的例子,很简单,技术含量不高,对于初学者可以学习下,下面开始吧。
第1、前面ASPX页面源码:
.ASPX Code [http://www.xueit.com]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SetGetCheckBoxList.aspx.cs" Inherits="SetGetCheckBoxList" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>如何设置与获取CheckBoxList多选的值。</title> </head> <body> <form id="form1" runat="server"> <div> <asp:CheckBoxList ID="chkList" runat="server"> <asp:ListItem Value="0">zero</asp:ListItem> <asp:ListItem Value="1">one</asp:ListItem> <asp:ListItem Value="2">two</asp:ListItem> </asp:CheckBoxList> <asp:Button ID="btnSet" runat="server" Text="Set" OnClick="btnSet_Click" /> <asp:Button ID="btnGet" runat="server" Text="Get" OnClick="btnGet_Click" /> </div> </form> </body> </html>
第2、.cs后台源码
.CS Code [http://www.xueit.com]
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class SetGetCheckBoxList : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnSet_Click(object sender, EventArgs e) { foreach (ListItem li in chkList.Items) { if (li.Value == "0") { li.Selected = true; continue; } if (li.Value == "1") { li.Selected = true; continue; } } } protected void btnGet_Click(object sender, EventArgs e) { string chkSelect = ""; for (int i = 0; i < chkList.Items.Count; i ) { if (chkList.Items[i].Selected == true) chkSelect = chkList.Items[i].Value ","; } if (chkSelect != "") chkSelect = chkSelect.Substring(0, chkSelect.Length - 1); else chkSelect = "空"; Response.Write("<script>alert('选中的值为:" chkSelect "')</script>"); } }
就这样简单就可以实现了。
精彩图集
精彩文章
热门标签
c语言知识点
location.hre
阻止冒泡
ProgressDial
java裁剪图片
一些用法
符号
站的
仿dedecms
Python异常处理
传递数据
dfs
position:fix
隐藏控件
Windows
常用方法
nextSibling
memcache扩展
自增号
硬盘使用
无参函数
阿里云
消息窗口
sink
Replica
链接类
选择法
竞争
将
c异或运算
屏幕锁定
金融
urldecode
ExpandableLi
所有进程
标准尺寸
连续元素
本周
语句练习
全文检索
greenlet
更新数据
新手入门
判断上传文件
路由失效
去除空格
swapoff
运行PHP
子序列
window.locat
指向
投影机
cmd窗口
实际
判定
simple_html_
文件 文件删除
format
创建图标
验证图片
赞助商链接
@CopyRight 2002-2008, 1SOHU.COM, Inc. All Rights Reserved QQ:1010969229

