Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Marking CheckBoxList Items as Checked

Reply
Thread Tools

Marking CheckBoxList Items as Checked

 
 
Wayne Wengert
Guest
Posts: n/a
 
      03-02-2005
I have a CheckBoxList with 11 items in the collection. I save the checked
item to a SQL DB, A record is created for each item checked for the current
customer.I want to redisplay checks in the fields that contain 1's when I
retrieve the records for that customer but I can't figure out the syntax to
do that? The chkList1.SelectedValue property deselects all other items and
the Items property appears to only accept an index. How can I do something
like:

While datareader1.Read
Select Case Category
Case "Gets Mailers"
cbList1.SelectedValue = "Gets Mailers" <== I really want to say
to check that selection
Case "Store Card"
cbList1.SelectedValue = "Store Card"
.......

End Select
End While

Thanks

Wayne


 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      03-02-2005
Wayne,

Instead of setting SelectedValue property of the list you should set
Selected property of every item you want to make selected.

Eliyahu

"Wayne Wengert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have a CheckBoxList with 11 items in the collection. I save the checked
> item to a SQL DB, A record is created for each item checked for the

current
> customer.I want to redisplay checks in the fields that contain 1's when I
> retrieve the records for that customer but I can't figure out the syntax

to
> do that? The chkList1.SelectedValue property deselects all other items and
> the Items property appears to only accept an index. How can I do something
> like:
>
> While datareader1.Read
> Select Case Category
> Case "Gets Mailers"
> cbList1.SelectedValue = "Gets Mailers" <== I really want to say
> to check that selection
> Case "Store Card"
> cbList1.SelectedValue = "Store Card"
> ......
>
> End Select
> End While
>
> Thanks
>
> Wayne
>
>



 
Reply With Quote
 
 
 
 
Wayne Wengert
Guest
Posts: n/a
 
      03-02-2005
Thanks for the reply.

Exactly how do I do that? I cannot figure out the syntax. There are lots of
choices in the Intellisense but nothing that makes sense to me for this. All
I want to do is to set the checkbox as checked for named values in the list.

Wayne


"Eliyahu Goldin" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Wayne,
>
> Instead of setting SelectedValue property of the list you should set
> Selected property of every item you want to make selected.
>
> Eliyahu
>
> "Wayne Wengert" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I have a CheckBoxList with 11 items in the collection. I save the

checked
> > item to a SQL DB, A record is created for each item checked for the

> current
> > customer.I want to redisplay checks in the fields that contain 1's when

I
> > retrieve the records for that customer but I can't figure out the syntax

> to
> > do that? The chkList1.SelectedValue property deselects all other items

and
> > the Items property appears to only accept an index. How can I do

something
> > like:
> >
> > While datareader1.Read
> > Select Case Category
> > Case "Gets Mailers"
> > cbList1.SelectedValue = "Gets Mailers" <== I really want to

say
> > to check that selection
> > Case "Store Card"
> > cbList1.SelectedValue = "Store Card"
> > ......
> >
> > End Select
> > End While
> >
> > Thanks
> >
> > Wayne
> >
> >

>
>



 
Reply With Quote
 
Wayne Wengert
Guest
Posts: n/a
 
      03-02-2005
This syntax seems to work:
cbList1.Items.Item("GE Music").Selected = True

The big confusion is that when you are keying in the statement and get to
the "Item" the popup indicates that it must be a zero based index. I did not
realize I could enter the value there.



Wayne



"Wayne Wengert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have a CheckBoxList with 11 items in the collection. I save the checked
> item to a SQL DB, A record is created for each item checked for the

current
> customer.I want to redisplay checks in the fields that contain 1's when I
> retrieve the records for that customer but I can't figure out the syntax

to
> do that? The chkList1.SelectedValue property deselects all other items and
> the Items property appears to only accept an index. How can I do something
> like:
>
> While datareader1.Read
> Select Case Category
> Case "Gets Mailers"
> cbList1.SelectedValue = "Gets Mailers" <== I really want to say
> to check that selection
> Case "Store Card"
> cbList1.SelectedValue = "Store Card"
> ......
>
> End Select
> End While
>
> Thanks
>
> Wayne
>
>



 
Reply With Quote
 
Wayne Wengert
Guest
Posts: n/a
 
      03-02-2005
When I load that out to my web site and run it I get the error:

Exception Details: System.FormatException: Input string was not in a correct
format.

Wayne

"Wayne Wengert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> This syntax seems to work:
> cbList1.Items.Item("GE Music").Selected = True
>
> The big confusion is that when you are keying in the statement and get to
> the "Item" the popup indicates that it must be a zero based index. I did

not
> realize I could enter the value there.
>
>
>
> Wayne
>
>
>
> "Wayne Wengert" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I have a CheckBoxList with 11 items in the collection. I save the

checked
> > item to a SQL DB, A record is created for each item checked for the

> current
> > customer.I want to redisplay checks in the fields that contain 1's when

I
> > retrieve the records for that customer but I can't figure out the syntax

> to
> > do that? The chkList1.SelectedValue property deselects all other items

and
> > the Items property appears to only accept an index. How can I do

something
> > like:
> >
> > While datareader1.Read
> > Select Case Category
> > Case "Gets Mailers"
> > cbList1.SelectedValue = "Gets Mailers" <== I really want to

say
> > to check that selection
> > Case "Store Card"
> > cbList1.SelectedValue = "Store Card"
> > ......
> >
> > End Select
> > End While
> >
> > Thanks
> >
> > Wayne
> >
> >

>
>



 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      03-02-2005
Something like this (C# syntax):
public void SetCheckedForValue (CheckBoxList cbl, string val)
{
for (int i=0; i<cbl.Count; i++)
if (cbl.Items[i].Value==val)
{
cbl.Items[i].Selected=true;
return;
}
}

Eliyahu

"Wayne Wengert" <(E-Mail Removed)> wrote in message
news:ucyd6$(E-Mail Removed)...
> Thanks for the reply.
>
> Exactly how do I do that? I cannot figure out the syntax. There are lots

of
> choices in the Intellisense but nothing that makes sense to me for this.

All
> I want to do is to set the checkbox as checked for named values in the

list.
>
> Wayne
>
>
> "Eliyahu Goldin" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Wayne,
> >
> > Instead of setting SelectedValue property of the list you should set
> > Selected property of every item you want to make selected.
> >
> > Eliyahu
> >
> > "Wayne Wengert" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > I have a CheckBoxList with 11 items in the collection. I save the

> checked
> > > item to a SQL DB, A record is created for each item checked for the

> > current
> > > customer.I want to redisplay checks in the fields that contain 1's

when
> I
> > > retrieve the records for that customer but I can't figure out the

syntax
> > to
> > > do that? The chkList1.SelectedValue property deselects all other items

> and
> > > the Items property appears to only accept an index. How can I do

> something
> > > like:
> > >
> > > While datareader1.Read
> > > Select Case Category
> > > Case "Gets Mailers"
> > > cbList1.SelectedValue = "Gets Mailers" <== I really want to

> say
> > > to check that selection
> > > Case "Store Card"
> > > cbList1.SelectedValue = "Store Card"
> > > ......
> > >
> > > End Select
> > > End While
> > >
> > > Thanks
> > >
> > > Wayne
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Wayne Wengert
Guest
Posts: n/a
 
      03-02-2005
Eliyahu;

Thank you. I think I understand what needs to be done now. I'll try this and
let you know the results.

Wayne

"Eliyahu Goldin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Something like this (C# syntax):
> public void SetCheckedForValue (CheckBoxList cbl, string val)
> {
> for (int i=0; i<cbl.Count; i++)
> if (cbl.Items[i].Value==val)
> {
> cbl.Items[i].Selected=true;
> return;
> }
> }
>
> Eliyahu
>
> "Wayne Wengert" <(E-Mail Removed)> wrote in message
> news:ucyd6$(E-Mail Removed)...
> > Thanks for the reply.
> >
> > Exactly how do I do that? I cannot figure out the syntax. There are lots

> of
> > choices in the Intellisense but nothing that makes sense to me for this.

> All
> > I want to do is to set the checkbox as checked for named values in the

> list.
> >
> > Wayne
> >
> >
> > "Eliyahu Goldin" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > Wayne,
> > >
> > > Instead of setting SelectedValue property of the list you should set
> > > Selected property of every item you want to make selected.
> > >
> > > Eliyahu
> > >
> > > "Wayne Wengert" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > I have a CheckBoxList with 11 items in the collection. I save the

> > checked
> > > > item to a SQL DB, A record is created for each item checked for the
> > > current
> > > > customer.I want to redisplay checks in the fields that contain 1's

> when
> > I
> > > > retrieve the records for that customer but I can't figure out the

> syntax
> > > to
> > > > do that? The chkList1.SelectedValue property deselects all other

items
> > and
> > > > the Items property appears to only accept an index. How can I do

> > something
> > > > like:
> > > >
> > > > While datareader1.Read
> > > > Select Case Category
> > > > Case "Gets Mailers"
> > > > cbList1.SelectedValue = "Gets Mailers" <== I really want

to
> > say
> > > > to check that selection
> > > > Case "Store Card"
> > > > cbList1.SelectedValue = "Store Card"
> > > > ......
> > > >
> > > > End Select
> > > > End While
> > > >
> > > > Thanks
> > > >
> > > > Wayne
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Wayne Wengert
Guest
Posts: n/a
 
      03-02-2005
It works! Thank you very much.

Wayne

"Wayne Wengert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Eliyahu;
>
> Thank you. I think I understand what needs to be done now. I'll try this

and
> let you know the results.
>
> Wayne
>
> "Eliyahu Goldin" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Something like this (C# syntax):
> > public void SetCheckedForValue (CheckBoxList cbl, string val)
> > {
> > for (int i=0; i<cbl.Count; i++)
> > if (cbl.Items[i].Value==val)
> > {
> > cbl.Items[i].Selected=true;
> > return;
> > }
> > }
> >
> > Eliyahu
> >
> > "Wayne Wengert" <(E-Mail Removed)> wrote in message
> > news:ucyd6$(E-Mail Removed)...
> > > Thanks for the reply.
> > >
> > > Exactly how do I do that? I cannot figure out the syntax. There are

lots
> > of
> > > choices in the Intellisense but nothing that makes sense to me for

this.
> > All
> > > I want to do is to set the checkbox as checked for named values in the

> > list.
> > >
> > > Wayne
> > >
> > >
> > > "Eliyahu Goldin" <(E-Mail Removed)> wrote in message
> > > news:%(E-Mail Removed)...
> > > > Wayne,
> > > >
> > > > Instead of setting SelectedValue property of the list you should set
> > > > Selected property of every item you want to make selected.
> > > >
> > > > Eliyahu
> > > >
> > > > "Wayne Wengert" <(E-Mail Removed)> wrote in message
> > > > news:(E-Mail Removed)...
> > > > > I have a CheckBoxList with 11 items in the collection. I save the
> > > checked
> > > > > item to a SQL DB, A record is created for each item checked for

the
> > > > current
> > > > > customer.I want to redisplay checks in the fields that contain 1's

> > when
> > > I
> > > > > retrieve the records for that customer but I can't figure out the

> > syntax
> > > > to
> > > > > do that? The chkList1.SelectedValue property deselects all other

> items
> > > and
> > > > > the Items property appears to only accept an index. How can I do
> > > something
> > > > > like:
> > > > >
> > > > > While datareader1.Read
> > > > > Select Case Category
> > > > > Case "Gets Mailers"
> > > > > cbList1.SelectedValue = "Gets Mailers" <== I really

want
> to
> > > say
> > > > > to check that selection
> > > > > Case "Store Card"
> > > > > cbList1.SelectedValue = "Store Card"
> > > > > ......
> > > > >
> > > > > End Select
> > > > > End While
> > > > >
> > > > > Thanks
> > > > >
> > > > > Wayne
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook Marking items read before I open them Daisy320 Microsoft Certification 1 04-27-2010 01:36 PM
CheckBox Checked=false when checked in DataList yurps ASP .Net 1 02-29-2008 01:08 PM
Looping through CheckBoxList items doesn't pick up selected ones when items were disabled Bart Van Hemelen ASP .Net 2 09-04-2006 08:35 AM
Marking an element as .checked and reading innerHTML sicapitan Javascript 4 08-26-2006 12:41 PM
javascript and checkboxlist values for items that are checked cindy ASP .Net Web Controls 1 05-08-2006 09:37 PM



Advertisments