I am working on a project that I want to "+Add Row" to. This will Add a row of four fields that are textboxes. The # of rows is variable so I created a literal control and have been doing

Protected Sub btnAddRow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddRow.Click
        Dim OfficeEquipmentRow As String = "<div class='EquipmentListing Equipment'><input type='text' Class='WorksheetInputStyle' ID='OfficeEquipment" & Session("OfficeRow") & "' runat='server'></div>"
        Dim OfficePriceRow As String = "<div class='EquipmentListing Price'><input type='text' Class='WorksheetInputStyle' ID='OfficePrice" & Session("OfficeRow") & "' runat='server'></div>"
        Dim OfficeQuantityRow As String = "<div class='EquipmentListing Quantity'><input type='text' Class='WorksheetInputStyle' ID='OfficeQuantity" & Session("OfficeRow") & "' runat='server'></div>"
        Dim OfficeTotalRow As String = "<div class='EquipmentListing Totals'><span Class='Totals' ID='OfficeTotal" & Session("OfficeRow") & "' runat='server'>$</span></div>          "

        litUpdate.Text += OfficeEquipmentRow & OfficePriceRow & OfficeQuantityRow & OfficeTotalRow
        Session("OfficeRow") = Session("OfficeRows") + 1
    End Sub

The only issue is when I hit Add Button again all the data that may have been input into the literal control's text boxes disappears. This will be very very annoying to the end user. How can I retain this information?

8 Years
Discussion Span
Last Post by MichaelWClark

I was able to resolve this issue on my own and with a bit of a point in the right direction. Here is the code to what I ended up doing. Hope it can help someone sometime! :D

Protected Sub btnAddRow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddRow.Click
        Session("row_click") = Session("row_click") + 1
        lblDate.Text = Session("row_click")
    End Sub

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    End Sub

    Public Function add_rows() As String

        Dim cnt As Integer = Session("row_click")
        lblPurchasePrice.Text = cnt.ToString
        'If Session("row_click") > 1 Then
        For x = 1 To cnt
            Dim OfficeEquipmentRow, OfficePriceRow, OfficeQuantityRow As TextBox
            Dim OfficeTotalRow As Label = New Label
            OfficeEquipmentRow = New TextBox
            OfficePriceRow = New TextBox
            OfficeQuantityRow = New TextBox


            OfficeEquipmentRow.ID = "OfficeEquipment" & x
            OfficePriceRow.ID = "OfficePrice" & x
            OfficeQuantityRow.ID = "OfficeQuantity" & x
            OfficeTotalRow.ID = "OfficeTotal" & x

            OfficeEquipmentRow.CssClass = "EquipmentListing Equipment"
            OfficePriceRow.CssClass = "EquipmentListing Price"
            OfficeQuantityRow.CssClass = "EquipmentListing Quantity"
            OfficeTotalRow.CssClass = "Totals"
        'End If
        Return vbNull
    End Function
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Session("row_click") = vbNull Then
            Session("row_click") = 1
        End If
        If Session("row_click") = 0 Then
            Session("row_click") = 1
        End If

    End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.