CheckListBox.checked

  • Thread starter Thread starter MSN
  • Start date Start date
M

MSN

xp pro/vs 2002/web forms/VB

How do I make a checkbox checked when add it to a checkboxlist.

Thanks
 
Hi MSN,

You can use the designer and than the collections and set selected to true,

Or you can do it in code than it is
\\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.CheckBoxList1.Items(0).Selected = True
End Sub
///
OR
In the aspx html page
\\\
<asp:CheckBoxList id="CheckBoxList1" style="Z-INDEX: 102; LEFT: 416px;
POSITION: absolute; TOP: 304px"
runat="server" Width="163px">
<asp:ListItem Value="Eerste" Selected="True">Eerste</asp:ListItem>
</asp:CheckBoxList>
///

I hope this helps?

Cor
 
Sorry, I missed the "web forms" for some reason...

I missed it as well, I am suprissed you saw it.
(I made the in my idea correct answer)

:-)

Cor
 
MSN,
Have you tried something like:

Dim item As New ListItem("apples")
item.Selected = True
CheckBoxList1.Items.Add(item)

Hope this helps
Jay
 
Hi Jay,

Look at the post from Herfried, therefore I made some extra work to correct
it.
(If Herfried is right, and in this case I assume that)

Cor
 
* "Cor Ligthert said:
Look at the post from Herfried, therefore I made some extra work to correct
it.

I still don't understand why Jay's solution should be wrong...
 
Hi,
I still don't understand why Jay's solution should be wrong...

Did I say that Herfried?

However that kind of answers you see not do me.

You are right.

Stuppid me.

Cor
 
Hi Herfried,
Sounded like that, but EOT ;-).
Not with that quoting, looks if I reals sayd that now.

I have once said that before when you quote you have to do that right.

You constructed now a negative message from me by deleting text, I know
another one who is very good in it.

That is the reason why I prefer Top quoting by the way.

Cor
 
Thanks for all the help so far

I tried this, it adds to the checklistbox the text and value but not
checked.

Dim NewItem as New ListItem
NewItem.Selected = True
NewItem.Text = drdReader!Product
NewItem.Value = drdReader!ProductID
chklstProducts.Items.Add(NewItem)

I have a list that I take from a database of products to create the
selections.
But when someone selects a record to edit I populate textboxes and I want to
check the selections that were stored in the database for that customer.

Thanks
 
Cor,
Huh?

What post from Herfried? The only post from Herfried (as well as you) in
this thread is about using the Windows Forms CheckBoxList?

Remember this is about the Web Forms!

I will look at MSN's second post and follow up.

Thanks
Jay
 
MSN,
The following works in VS.NET 2003.

Dim item As ListItem

item = New ListItem
item.Selected = True
item.Text = "Product1"
item.Value = "1"
CheckBoxList1.Items.Add(item)

item = New ListItem
item.Selected = False
item.Text = "Product2"
item.Value = "2"
CheckBoxList1.Items.Add(item)

item = New ListItem
item.Selected = True
item.Text = "Product3"
item.Value = "3"
CheckBoxList1.Items.Add(item)

The first & third item will be checked, the second will not.

Hope this helps
Jay
 
thank you

Jay B. Harlow said:
MSN,
The following works in VS.NET 2003.

Dim item As ListItem

item = New ListItem
item.Selected = True
item.Text = "Product1"
item.Value = "1"
CheckBoxList1.Items.Add(item)

item = New ListItem
item.Selected = False
item.Text = "Product2"
item.Value = "2"
CheckBoxList1.Items.Add(item)

item = New ListItem
item.Selected = True
item.Text = "Product3"
item.Value = "3"
CheckBoxList1.Items.Add(item)

The first & third item will be checked, the second will not.

Hope this helps
Jay

want
 
Hi Jay,

No mine is as well for the webform, I did give it for using the designer,
using vb code and using direct ASP/HTML, however forget it, I did read your
message wrong while it is very well alternative on the methode I showed.

Was my mistake reading your post,

Sorry

Cor
What post from Herfried? The only post from Herfried (as well as you) in
this thread is about using the Windows Forms CheckBoxList?
 
Cor,
Doh! It would appear that we both read messages wrong in this thread!

As you now realize my original message added to your message without taking
anything away.

Your comments to Herfried, then your continued comments to me, lead me to
believe you inadvertently gave a Winform answer instead of a Webform answer.
I'm not sure if Herfried's answer really counts either way as I get a
compile error on VS.NET 2003 with it, however CheckBoxList is a web control.
Herfried's fails with: "Overload resolution failed because no accessible
'Add' accepts this number of arguments"

Jay
 
Back
Top