如何确定的CheckBoxList选中/选定 - [英] how to determine checkboxlist is checked/selected -

查看:395
本文介绍了如何确定的CheckBoxList选中/选定 - 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行codeI得到4 checkboxs和我检查/选择的所有4复选框,当我尝试调试code,它的确算,我有4个复选框,但选定的所有4复选框= FALSE

我所缺少code?

 < ASP:的CheckBoxList ID =CHK=服务器ondatabinding =chk_DataBinding
   ondatabound =chk_DataBound>
< / ASP:&的CheckBoxList GT;清单<串GT;角色=新的List<串GT;(); 的for(int i = 0; I< chk.Items.Count;我++)
 {
     如果(chk.Items [I] .Selected)
    {
        roles.Add(chk.Items [I]。价值);
    }
 }


解决方案

您的逻辑是一致的基本的CheckBoxList 上的 ListControl.Items 页面,从个人的经验,检查的 .Selected 属性列表项应该可以正常工作。

检查以确保您不会重新填充的CheckBoxList 你打如果选中逻辑之前 - 如果我猜,我会说有一个很好的机会,你在每一个回传丢失的名单。简单的解决方法是不要叫你的数据绑定的逻辑,如果它是一个回发。

when i execute the code i get 4 checkboxs and i checked/selected all 4 checkbox and when i try to debug the code, it does count that i have 4 checkbox but all 4 checkbox is selected=false.

what i am missing in code?

<asp:checkboxlist id="chk" runat="server" ondatabinding="chk_DataBinding"
   ondatabound="chk_DataBound">
</asp:checkboxlist>

List<String> roles = new List<string>();

 for (int i = 0; i < chk.Items.Count; i++)
 {
     if (chk.Items[i].Selected)
    {
        roles.Add(chk.Items[i].Value);
    }
 }

解决方案

Your logic is consistent with the basic CheckBoxList given on the ListControl.Items page, and from personal experience, checking the .Selected property of the ListItem should work fine.

Check to make sure you aren't re-populating the CheckBoxList before you hit the "if checked" logic - if I had to guess, I'd say there's a good chance you're losing the list on every postback. The simple solution is don't call your databinding logic if it's a postback.

这篇关于如何确定的CheckBoxList选中/选定 - 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆