Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 9-Sep-10 21:24pm
v3
Comments
Dalek Dave 10-Sep-10 3:24am    
Edited for Grammar and Readability.

1 solution

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]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900