Pre Selecting CheckBoxList

P

Patrick.O.Ige

I have some boolean value(1 or 0 ) in a table and i want a databinded
CheckBoxList
to present the selected values on the page..
With CheckBox i know i can se the Checked property like so :-
<asp:CheckBox id="chk" checked=<% Databind.Eval("This returns 1 or 0")%>
runat="server"%>
Any help how i can do it using CheckBoxList?
 
G

Guest

If your datasource has the columns to define the items in the checkbox list
and the boolean field you can iterate through your data source and use the
boolean field to set the item's selected property. Items in your
checkboxlist must be in the same order of your data source, so you are
sorting a dataview, do so before binding to the checkboxlist. Using a
DataView it would be something like this.

//any sorting you want
checkboxlist.datasource = dataview;
checkboxlist.datatextfield = "description column in data view"
checkboxlist.datavaluefield = "value column in data view, can be omitted if
same as textfield";
checkboxlist.databind();
//iterate through the rows of the dataview with for loop
for(int i = 0; i < dataview.count; i++){
checkboxlist.items = (bool)dataview["boolean field"];
}

this is of course untested and obviously pseudocode.
 
P

Patrick.O.Ige

Thx for the reply John.
'm not using a DataView..
What i have is a Databinded Checkboxlist.
I have the boolean values in a column table how would i loop though the
checkboxlist and retrieve it
I want to retirieve it as TRUE or FALSE so that on getting to the client is
Checked if 1 and unchecked if false or 0


..

John Teague said:
If your datasource has the columns to define the items in the checkbox list
and the boolean field you can iterate through your data source and use the
boolean field to set the item's selected property. Items in your
checkboxlist must be in the same order of your data source, so you are
sorting a dataview, do so before binding to the checkboxlist. Using a
DataView it would be something like this.

//any sorting you want
checkboxlist.datasource = dataview;
checkboxlist.datatextfield = "description column in data view"
checkboxlist.datavaluefield = "value column in data view, can be omitted if
same as textfield";
checkboxlist.databind();
//iterate through the rows of the dataview with for loop
for(int i = 0; i < dataview.count; i++){
checkboxlist.items = (bool)dataview["boolean field"];
}

this is of course untested and obviously pseudocode.


Patrick.O.Ige said:
I have some boolean value(1 or 0 ) in a table and i want a databinded
CheckBoxList
to present the selected values on the page..
With CheckBox i know i can se the Checked property like so :-
<asp:CheckBox id="chk" checked=<% Databind.Eval("This returns 1 or 0")%>
runat="server"%>
Any help how i can do it using CheckBoxList?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top