By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,137 Members | 2,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,137 IT Pros & Developers. It's quick & easy.

Pre Selecting CheckBoxList

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.