复选框列表项中的问题... [英] problem in checkboxlist item ...

查看:92
本文介绍了复选框列表项中的问题...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

for (int i = 0; i < dt.Rows.Count; i++)
{
    foreach(CheckBox chk in Chklst.Items)
    {
        if (chk.Text.IndexOf(dt.Rows[0][0].ToString()) > 0)
        {
            chk.Checked = true;
        }
        else
        {
            chk.Checked = false;
        }
    }
}

我在这里遇到问题

我在这4个列表项中都有核对清单.
我正在用db签入,如果值已经在db中,则会被检查,否则未选中..

在这里,我带了临时的脸颊盒chk.如何将温度复选框与cheklistbox进行比较

我在这里遇到的错误是
无法将类型为"System.Web.UI.WebControls.ListItem"的对象转换为类型为"System.Web.UI.WebControls.CheckBox"的对象.

怎么做???? plz帮助我

i am getting problem here

i have checkboxlist in this 4 list items.
i am checkin with db if value is already in db it get checked else unchecked..

here i took temp cheeck box chk. how to compare temp checkBox with cheklistbox

the error what i am gettin here is
Unable to cast object of type ''System.Web.UI.WebControls.ListItem'' to type ''System.Web.UI.WebControls.CheckBox''.

how to do ????plz help me

推荐答案

我认为在这里,我们检查检查清单项目的索引(而不是验证存储在表中的值)

只需将检查表的值与数据表中的值进行比较
I think here ur checking for the indexof the checklistitem(instead of verifying the value which is stored in a table)

just compare the value of the checklist and the value in the datatable


您会在for循环的变量"i"中生成一组整数索引,但您永远不会使用变量"'我在循环中.

如果(chk.Text.IndexOf(dt.Rows [0] [0] .ToString())> 0)"

IndexOf返回一个整数...然后将该整数转换为字符串,然后将其与整数进行比较...应该会在此处产生编译错误.
You generate a set of integer indexes in the variable ''i in the outer for loop, but you never use the variable ''i in the loop.

"if (chk.Text.IndexOf(dt.Rows[0][0].ToString()) > 0)"

IndexOf returns an integer ... then you convert that integer to a string, and then you compare it to an integer ... that should give you a compile error right there.


这篇关于复选框列表项中的问题...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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