Marking CheckBoxList Items as Checked

Discussion in 'ASP .Net' started by Wayne Wengert, Mar 2, 2005.

  1. 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
    Wayne Wengert, Mar 2, 2005
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    >
    >
    Eliyahu Goldin, Mar 2, 2005
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
    Wayne Wengert, Mar 2, 2005
    #3
  4. Got it (I think)!

    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" <> wrote in message
    news:...
    > 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
    >
    >
    Wayne Wengert, Mar 2, 2005
    #4
  5. NOT!

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
    Wayne Wengert, Mar 2, 2005
    #5
  6. Something like this (C# syntax):
    public void SetCheckedForValue (CheckBoxList cbl, string val)
    {
    for (int i=0; i<cbl.Count; i++)
    if (cbl.Items.Value==val)
    {
    cbl.Items.Selected=true;
    return;
    }
    }

    Eliyahu

    "Wayne Wengert" <> wrote in message
    news:ucyd6$...
    > 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" <> wrote in message
    > news:%...
    > > 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" <> wrote in message
    > > news:...
    > > > 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
    > > >
    > > >

    > >
    > >

    >
    >
    Eliyahu Goldin, Mar 2, 2005
    #6
  7. 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" <> wrote in message
    news:...
    > Something like this (C# syntax):
    > public void SetCheckedForValue (CheckBoxList cbl, string val)
    > {
    > for (int i=0; i<cbl.Count; i++)
    > if (cbl.Items.Value==val)
    > {
    > cbl.Items.Selected=true;
    > return;
    > }
    > }
    >
    > Eliyahu
    >
    > "Wayne Wengert" <> wrote in message
    > news:ucyd6$...
    > > 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" <> wrote in message
    > > news:%...
    > > > 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" <> wrote in message
    > > > news:...
    > > > > 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
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Wayne Wengert, Mar 2, 2005
    #7
  8. It works! Thank you very much.

    Wayne

    "Wayne Wengert" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    > > Something like this (C# syntax):
    > > public void SetCheckedForValue (CheckBoxList cbl, string val)
    > > {
    > > for (int i=0; i<cbl.Count; i++)
    > > if (cbl.Items.Value==val)
    > > {
    > > cbl.Items.Selected=true;
    > > return;
    > > }
    > > }
    > >
    > > Eliyahu
    > >
    > > "Wayne Wengert" <> wrote in message
    > > news:ucyd6$...
    > > > 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" <> wrote in message
    > > > news:%...
    > > > > 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" <> wrote in message
    > > > > news:...
    > > > > > 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
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Wayne Wengert, Mar 2, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rik
    Replies:
    0
    Views:
    3,208
  2. yurps
    Replies:
    1
    Views:
    6,871
    rajeshthangarasu1983
    Feb 29, 2008
  3. Bart Van Hemelen
    Replies:
    2
    Views:
    4,655
    Bart Van Hemelen
    Sep 4, 2006
  4. cindy
    Replies:
    1
    Views:
    1,079
    Phillip Williams
    May 8, 2006
  5. sicapitan
    Replies:
    4
    Views:
    171
    sicapitan
    Aug 26, 2006
Loading...

Share This Page