复选框列表项中的问题...

编程入门 行业动态 更新时间:2024-10-24 22:20:35
本文介绍了复选框列表项中的问题...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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.

更多推荐

复选框列表项中的问题...

本文发布于:2023-10-12 23:20:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1486171.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复选框   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!