日期:2014-05-18  浏览次数:20509 次

怎么获取datalist中的checkboxlist选中的值?
不知哪里出错,老是得不到值,得到的结果是空。请大家帮忙解决一下,谢谢。
我要做的是:在datalist外一个button后,获取到datalist中checkboxlist时里面选中的值,现在不行了。郁闷。
代码是这样写的:
  protected   void   AddRight()
        {
                int   roleId   =   Convert.ToInt32(Request.QueryString[ "RoleId "]);


                for   (int   i   =   0;   i   <=   dlstModuleRight.Items.Count   -   1;   i++)
                {
                        CheckBoxList   chkRights   =   (CheckBoxList)dlstModuleRight.Items[i].FindControl( "chkRoleRight ");


                        //此句可以攻取ModuleId
                        Label   lblId   =   (Label)dlstModuleRight.Items[i].FindControl( "lblModuleId ");


                       
                        for(int   j=0;j <=chkRights.Items.Count-1;   j++)
                        {
                                if   (chkRights.Items[j].Selected   ==   true)
                                {
                                        Response.Write(chkRights.Items[j].Text);

                                }
                                else
                                {
                                        Response.Write(j);
                                }

                        }
                 
麻烦大家帮忙,在线结分,谢谢。

                     


                }

------解决方案--------------------
第一个常识问题..

是否判断回传
private void Page_Load(object sender, System.EventArgs e)
{
if (! IsPostBack )
{
//绑定数据
}
}
------解决方案--------------------
这句话有问题
CheckBoxList chkRights = (CheckBoxList)dlstModuleRight.Items[i].FindControl( "chkRoleRight ");

明白你在后台给他们命了chkRoleRight这个名称
但是生成的aspx页面中就不是这个名字了
------解决方案--------------------
你可以获得包含的控件,然后用。。Controls[0]。。这种方法来