checking a checkbox control at runtime based on literal value?

M

Moe Sizlak

Hi,

Can I check a checkbox by default based on the value returned from a
database? for example if the value (dr("frm7value")) returned from a db
field is "YES" how can I check the checkbox by default?

Moe
 
M

Mike Smith

yup in .Net u can bind any property to a data source
so in this case u would have to bind the checkbox selected property to that
particular field and it should give u the desired result (as long as the
field stores the correct value it requires)
 
M

Mike Smith

ive got a demo (winForms) i did showing how to bind data to various
properties of controls (standard text, images and even the font color
property... )
was thinkin abt uploading it to planetsourcecode.com (just need to comment
the code nicely)

but what u need is to just bind the checkboxs selected property.

Scenario 1
If you already have the dataset on the designer u link it via the property
box.
1. Select the checkbox, browse the DataBinding property and link it to
the desired
DataSet.DataTable.Field

Scenario 2
If you are doing it thru code , then u need to write the databinding code
via.
CheckBox1.DataBindings.Add("Checked", Ds1,"Employees.Status")

where "Checked" is the property, DS1 is the datasource (dataset name) and
the Employees.Status is the datafield to be bound to (employees datatable
and Status field)

Note: I used a bit datatype for my Status field to be linked to the Checked
propery of the checkBox.

The above code is for winForms....
In asp.Net the equivalent would be the same for both Scenario 1 and 2 just
make sure DS1 is available prior to page load (page level declaration would
work):

<asp:CheckBox id="CheckBox1" runat="server" Checked='<%#
DataBinder.Eval(Ds1, "Tables[Employees].DefaultView.[0].Status") %>'>
</asp:CheckBox>


HTH..

Mike...
http://bikesh.europe.webmatrixhosting.net
http://www.planetsourcecode.com (search keyword : phoetus)
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top