Looking in a cookie collection to preselect checklistbox items

Discussion in 'ASP .Net' started by D. Shane Fowlkes, Apr 7, 2004.

  1. I have a form with a CheckBoxList which is created from a SQLDataReader. It
    contains Staff personnel and I use the ID and LogOnName (a string) to build
    the CBL. All works fine. I also have a "Remember my settings" checkbox on
    the form that if checked, will run a sub routine to create a cookie to store
    the IDs of the checked names in the CBL. The idea is to have the form
    "remember" the user's selections so when they come back to the form at a
    later time, their checkboxes are filled in for them and they can just click
    Submit.

    I can create the cookie just fine. But I'm having trouble with creating the
    logic to look "in" the cookie to look for any Staff IDs to preselect the
    checkboxes. In theory, I could after the databinding of the CBL, I could
    then loop thru all the CBL Items and see if it's found in the cookie, if so,
    simply check the checkbox and move to the next item. Etc.

    Make sense? So how do I look in the cookie and make that connection??



    The contents of my sample cookie:

    DRPT-Intranet-Project-Search-ProjMgrs|12=selected&10=selected&16=selected
    ....etc

    '****************************************
    Sub CreateCookie()
    Dim objCookie As HTTPCookie
    Dim itmProjMgrs As ListItem

    objCookie = New HTTPCookie("DRPT-Intranet-Project-Search-ProjMgrs")
    objCookie.Expires = DateTime.MaxValue

    If chkRememberSettings.Checked = True Then

    'Saving Selected Project Managers
    For Each itmProjMgrs In chkProjMgrs.Items

    If itmProjMgrs.Selected Then
    objCookie.Values(itmProjMgrs.Value) = "selected"
    End If

    Next

    Else
    'Nothing...hopefully, creates an empty cookie
    End If

    Response.Cookies.Add(objCookie)

    End Sub
    '****************************************


    And this is within a sub I use to build the CheckBoxList from a
    SQLDataReader:


    ....etc

    objCookie = Request.Cookies("DRPT-Intranet-Project-Search-ProjMgrs")

    For Each itmProjMgrs In chkProjMgrs.Items
    'what here? Here's where I need to determine which checkboxes should be
    checked..
    Next
     
    D. Shane Fowlkes, Apr 7, 2004
    #1
    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. Isaac Wang via .NET 247

    How to preselect multiple items in listbox

    Isaac Wang via .NET 247, Apr 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,974
    =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=
    Apr 27, 2004
  2. =?Utf-8?B?VGltOjouLg==?=

    Preselect item in DropdownList Edit mode???

    =?Utf-8?B?VGltOjouLg==?=, Dec 28, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,550
    =?Utf-8?B?UmFodWwgQW5hbmQ=?=
    Dec 29, 2004
  3. Øyvind Isaksen
    Replies:
    1
    Views:
    999
    Øyvind Isaksen
    May 18, 2007
  4. Christiaan Nieuwlaat

    How can I get selected Checklistbox Items to Literal in Placeholde

    Christiaan Nieuwlaat, May 25, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    269
    Brock Allen
    May 30, 2005
  5. Joel Barsotti

    Can preselect databound listbox items

    Joel Barsotti, Jan 4, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    141
    Joel Barsotti
    Jan 4, 2007
Loading...

Share This Page