469,602 Members | 2,012 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Pre Selecting CheckBoxList

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?
Nov 19 '05 #1
2 5053
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[i] = (bool)dataview[i]["boolean field"];
}

this is of course untested and obviously pseudocode.
"Patrick.O.Ige" wrote:
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?

Nov 19 '05 #2
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" <Jo********@discussions.microsoft.com> wrote in message
news:B0**********************************@microsof t.com...
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[i] = (bool)dataview[i]["boolean field"];
}

this is of course untested and obviously pseudocode.
"Patrick.O.Ige" wrote:
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?

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Bryce Budd | last post: by
4 posts views Thread by dm_dal | last post: by
4 posts views Thread by Shaul Feldman | last post: by
9 posts views Thread by CCORDON | last post: by
4 posts views Thread by Patrick.O.Ige | last post: by
4 posts views Thread by adiweb | last post: by
5 posts views Thread by stephen | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.