我有一个复选框列表,我在页面加载时将它与sqldatsource绑定在一起...... [英] I have a checkboxlist i bind it with sqldatsource on page load ............
问题描述
我有一个复选框列表,并在页面加载时将其与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 anobject
which must be cast appropriately: just using theToString()
method will not necessarily return anything which matches the content of the CheckBoxList.
This means theFindByText
method fails, and returns a null.
[edit]Spelling and clarification - OriginalGriff[/edit]
这篇关于我有一个复选框列表,我在页面加载时将它与sqldatsource绑定在一起......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!