Results 1 to 3 of 3

Thread: Display array values on page one at a time

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    8

    Question Display array values on page one at a time

    Hi,

    I have an ASP .net page that contains a label and a NEXT button.

    I want to display in the label, array values one at a time as the next button is pushed. This is the foundation that I will build further functionality on. This seems so simple, but I can’t figure out how to do it – I am new to asp .net. I’m trying to increment a counter to go through the array, but the counter keeps getting reset to zero. I hope someone can help me. THANKS! Here is my code:

    Public Class AssignRecTypePerms
    Inherits System.Web.UI.Page
    Dim ctr As Integer

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If Not Page.IsPostBack Then
    Dim SCArray(,) = CType(Session.Item("SessSCArray"), Array)
    lblSchoolCode.Text = SCArray(1, 0)
    ctr = 0
    End If
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click

    Dim SCArray(,) = CType(Session.Item("SessSCArray"), Array)
    ctr = ctr + 1
    lblSchoolCode.Text = SCArray(1, ctr)

    End Sub
    End Class

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Display array values on page one at a time

    Using class level variables is dangerous in asp. Try using a session variable:
    VB Code:
    1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2. If Not Page.IsPostBack Then
    3. Dim SCArray(,) = CType(Session.Item("SessSCArray"), Array)
    4. lblSchoolCode.Text = SCArray(1, 0)
    5. session("ctr") = 0
    6. End If
    7. End Sub
    8.  
    9. Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
    10.  
    11. Dim SCArray(,) = CType(Session.Item("SessSCArray"), Array)
    12. session("ctr") = directcast(session("ctr"),int32) + 1
    13. lblSchoolCode.Text = SCArray(1, directcast(session("ctr"),int32) )
    14.  
    15. End Sub
    Last edited by wild_bill; Aug 29th, 2006 at 10:57 AM.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Display array values on page one at a time

    Because you've declared ctr, and ctr is not assigned the value in the session object at all. In fact, I don't see where ctr is being incremented.

    Store CTR in Viewstate or Session.

Posting Permissions

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



Click Here to Expand Forum to Full Width