Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2005
    Posts
    47
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Remembering state of datalist controls

    hello,

    I have a datalist control. Each item has a checkbox and each checkbox has possible options that are shown as a radio button list when the user checks the box. i have a button later in the form for adding a file to the entry which causes a post back. now when this happens i lose my state from the checkboxes and such.

    Is there an easy way to keep the posted data from my datalist?

    i have done a similar thing on this same page that saves the filenames and ids and such of each file that is added as a string collection(delimeted with ",") to a structure stored as a session variable.

    Code:
      If Session.Item("smsg") Is Nothing Then
                    smsg.StrFileCol = New StringCollection
                    smsg.StrFlagCol = New StringCollection
                    Session.Add("smsg", smsg)
                    smsg = CType(Session.Item("smsg"), SM_Message)
                Else
                    smsg = CType(Session.Item("smsg"), SM_Message)
                    'Me.txtTitle.Text = smsg.MessageTitle.ToString
                    If Not (smsg.StrFlagCol.Count = 0) Then
    
                    End If
                    If Not (smsg.StrFileCol.Count = 0) Then
                        For i As Integer = 0 To smsg.StrFileCol.Count - 1
                            Dim item As New ListItem
                            Dim str() As String = Split(smsg.StrFileCol(i), ",")
                            '0 location               
                            '1 name
                            '2 caption
                            '3 type
                            '4 id
                            item.Text = str(1).ToString
                            item.Value = str(4).ToString
                            Me.lboxFileUpload.Items.Add(item)
    
                        Next
                    End If
    
    
    
    ' i initially thought i could handle the flags in a way similar to this
    'i should be able to create a string for the flag collection that is "," delimeted with 0 being flag name, 1 checked or not, 2 index of radio thats clicked
    
                            'For Each ctrl As Control In Me.dlFlags.Controls
                            '    Dim ckbx As CheckBox
                            '    ckbx = CType(ctrl, CheckBox)
    
                            '    If Request.Form(ckbx.ID) = "Checked" Then
                            '        ckbx.Checked = True
    
                            '    End If
    
    
    
                            'Next

    If anyone has ever done a similar method for an order form or survey etc. I would very much appreciate the insight.

    Im really not sure how i would do this in a repeated control

    Thanks in advance
    DrewG
    Last edited by werD; 06-06-2007 at 10:53 PM.

  • #2
    New Coder
    Join Date
    Feb 2005
    Posts
    47
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ive tried adusting this a bit

    im now loading the flag stringcollection like so

    Code:
        For Each itm As DataListItem In Me.dlFlags.Items
                        Dim chkbx As CheckBox = CType(itm.FindControl("chkFlag"), CheckBox)
                        Dim rdos As RadioButtonList = CType(itm.FindControl("rdoparam"), RadioButtonList)
                        Dim str As String = ""
                        If chkbx.Checked = True Then
                            If Not (rdos.SelectedIndex = -1) Then
                                str = chkbx.Text & ","
                                str &= rdos.SelectedValue
                            Else
                                str = chkbx.Text & ","
                                str &= 0
                            End If
                            smsg.StrFlagCol.Add(str)
                        End If
                    Next

    and im attempting to check the values on databind like so

    Code:
     Protected Sub dlFlags_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlFlags.ItemDataBound
           
            Dim chk As CheckBox = CType(e.Item.FindControl("chkFlag"), CheckBox)
            Dim xDs As XmlDataSource = xmldsflagparams
            Dim hdn As HiddenField = CType(e.Item.FindControl("hdnFlagId"), HiddenField)
    
            Dim rdo As RadioButtonList = CType(e.Item.FindControl("rdoparam"), RadioButtonList)
            xDs.XPath = "//flag[@id='" & hdn.Value & "']//param"
            rdo.DataSourceID = ""
            rdo.DataSource = xDs
            rdo.DataBind()
            Dim spn As HtmlGenericControl = CType(e.Item.FindControl("spanradiolist"), HtmlGenericControl)
            If Not (smsg.StrFlagCol.Count = 0) Then
                For Each flag As String In smsg.StrFlagCol
                    Dim strflag() As String = Split(flag, ",")
                    If strflag(0) = chk.Text Then
                        chk.Checked = True
                    End If
                    If strflag(1) > 0 Then
                        rdo.SelectedValue = strflag(1)
                        spn.Style.Value = "display:inline;"
                    End If
    
                Next
            End If
    unfortunately the state of the datalist is identical to the first page load

    here's a shortened verison of the page load method
    Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not Page.IsPostBack Then
                Dim strid As String = Request.QueryString("q")
                If Not (strid Is Nothing) Then
                    If ISCaptain(strid) Then
                        If CheckUser(strid) Then
                            StartPage(strid)
                            Me.pnlAddEntry.Visible = True
                            Session.Item("smsg") = Nothing
                            If Session.Item("smsg") Is Nothing Then
                                smsg.MessageId = New Guid(strid)
                                smsg.StrFileCol = New StringCollection
                                smsg.StrFlagCol = New StringCollection
                                Session.Add("smsg", smsg)
                                smsg = CType(Session.Item("smsg"), SM_Message)
                            End If
    
                        Else
                            Me.pnlUnAuth.Visible = True
                            Me.pnlAddEntry.Visible = False
                        End If
                    Else
       
                        Me.pnlCaptain.Visible = True
                        Me.pnlAddEntry.Visible = False
                    End If
                End If
            Else
                Me.pnlAddEntry.Visible = True
    
                If Session.Item("smsg") Is Nothing Then
                    smsg.StrFileCol = New StringCollection
                    smsg.StrFlagCol = New StringCollection
                    Session.Add("smsg", smsg)
                    smsg = CType(Session.Item("smsg"), SM_Message)
                Else
                    smsg = CType(Session.Item("smsg"), SM_Message)
                    'Me.txtTitle.Text = smsg.MessageTitle.ToString
                    If Not (smsg.StrFlagCol.Count = 0) Then
    
                    End If
                    If Not (smsg.StrFileCol.Count = 0) Then
                        For i As Integer = 0 To smsg.StrFileCol.Count - 1
                            Dim item As New ListItem
                            Dim str() As String = Split(smsg.StrFileCol(i), ",")
                            '0 location               
                            '1 name
                            '2 caption
                            '3 type
                            '4 id
                            item.Text = str(1).ToString
                            item.Value = str(4).ToString
                            Me.lboxFileUpload.Items.Add(item)
                        Next
                    End If
                   
                End If
            End If
        End Sub
    it appears that strflagcol is always returning a 0 value??

    thanks
    Last edited by werD; 06-07-2007 at 12:13 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •