Love in coding...

    Free and Susan

统计

积分与排名

techLINKS

友情链接

最新评论

借助HiddenText 确定CheckBoxList当前的操作类型及点击的CheckBox

本次示例主要是解决
CheckBoxList这样的List控件
在引发SelectedIndexChanged事件时
本身不能直接得到当前的操作Item
以及是哪种操作类型 选中? 还是 取消选中?
-----------
示例代码如下:

 1protected void Page_Load(object sender, EventArgs e)
 2    {
 3        if (!IsPostBack)
 4        {
 5            //绑定CheckBoxList操作
 6            this.hidtxt_CheckBoxSelectValue.Value = "";//第一次绑定完CheckBoxList
 7        }

 8    }

 9
10    protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
11    {
12        //hidtxt_CheckBoxSelectValue 存储的是上次的点选值
13        //如果上次是Page_Load 则hidtxt_CheckBoxSelectValue为空
14        string sOld = this.hidtxt_CheckBoxSelectValue.Value.Trim();
15
16        for (int i = 0; i < CheckBoxList1.Items.Count; i++)
17        {
18            //第一种情况
19            //原来没有选中 当前却选中 
20            //则本次点击操作是:选中 并且点选的是这一个Item
21            if (CheckBoxList1.Items[i].Selected)
22            {
23                if (!sOld.Contains(CheckBoxList1.Items[i].Value.Trim() + ","))
24                {
25                    //进行相关处理
26                    Response.Write("本次是选中操作,操作的CheckBox的Text值是" + CheckBoxList1.Items[i].Text + "其Value值是" + CheckBoxList1.Items[i].Value);
27                    i = CheckBoxList1.Items.Count ;
28                }

29            }

30            else
31            {
32                //第二种情况
33                //原来有选中 当前却没选中 
34                //则本次点击操作是:取消选中 并且点选的是这一个Item
35                if (sOld.Contains(CheckBoxList1.Items[i].Value.Trim() + ","))
36                {
37                    //进行相关处理
38                    Response.Write("本次是取消选中操作,操作的CheckBox的Text值是" + CheckBoxList1.Items[i].Text + "其Value值是" + CheckBoxList1.Items[i].Value);
39                    i = CheckBoxList1.Items.Count;
40                }

41            }

42        }

43
44        //保存这次的所有选中的值
45        string sNew = "";
46        foreach (ListItem item in CheckBoxList1.Items)
47        {
48            if (item.Selected)
49                sNew += " " + item.Value.Trim() + ",";
50        }

51        this.hidtxt_CheckBoxSelectValue.Value = sNew;//为下一次的比较做准备        
52    }

posted on 2007-01-11 17:59 freeliver54 阅读(348) 评论(1)  编辑 收藏 网摘 所属分类: VS技術實踐

评论

#1楼[楼主] 2008-07-29 17:17 freeliver54      

通过Request.Form得到CheckBoxList当前所点选项的索引值
http://www.cnblogs.com/freeliver54/archive/2008/07/29/1255749.html" target="_new">http://www.cnblogs.com/freeliver54/archive/2008/07/29/1255749.html
  回复  引用  查看    




发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 617988




相关文章:

相关链接: