我有一个复选框列表,我在页面加载时将它与sqldatsource绑定在一起...... [英] I have a checkboxlist i bind it with sqldatsource on page load ............

查看:72
本文介绍了我有一个复选框列表,我在页面加载时将它与sqldatsource绑定在一起......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复选框列表,并在页面加载时将其与sqldatsource绑定.

我检查了dr ["DepartmentName"]的值.

我检查
chkDepartments.Items.FindByText(dr["DepartmentName"].ToString());


但是,
尽管dr ["DepartmentName"]保留一个值,但发现chkDepartments.Items.FindByText(dr["DepartmentName"].ToString())为空.

调试还表明,在此阶段,项目具有Datatextfield和datavaluefield作为system.data.datarow.

I have a checkboxlist and I bind it with sqldatsource on page load.

I check the value of dr["DepartmentName"].

I check
chkDepartments.Items.FindByText(dr["DepartmentName"].ToString());


However,
chkDepartments.Items.FindByText(dr["DepartmentName"].ToString()) is found to be null although dr["DepartmentName"] holds a value.

Also debugging shows that at this stage items have Datatextfield and datavaluefield as system.data.datarow.

推荐答案

DataReader返回必须正确转换的object:使用ToString()方法不一定会返回与CheckBoxList内容匹配的任何内容.

这意味着FindByText方法失败,并返回null.

[edit]拼写和说明-OriginalGriff [/edit]
A DataReader returns an object which must be cast appropriately: just using the ToString() method will not necessarily return anything which matches the content of the CheckBoxList.

This means the FindByText method fails, and returns a null.

[edit]Spelling and clarification - OriginalGriff[/edit]


这篇关于我有一个复选框列表,我在页面加载时将它与sqldatsource绑定在一起......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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