Results 1 to 3 of 3

Thread: Displaying record # for each record in a datalist

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Location
    Phoenix, AZ
    Posts
    22

    Unhappy Displaying record # for each record in a datalist

    I’ve got a working datalist going; the only thing is that I can’t seem to display properly the record number for each record. I’m trying to use a For...Next loop within an If Not Page.IsPostBack and I keep getting an error. Here is my code.
    Code:
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Not Page.IsPostBack() Then
                lblPageSize.Text = "5"
                lblCurrIndex.Text = "0"
                SQLBind()
            End If
        End Sub
    
        Private Sub SQLBind()
            Dim objConn As New SqlConnection("My connection info;")
            Dim objDA As New SqlDataAdapter("SELECT contactID_pk, name, message, dateCreated FROM contactUs", objConn)
            Dim objDS As New DataSet()
    
            If Not Page.IsPostBack() Then
                Dim intCounter As Integer 'Holds counter for loop
                Dim intNewCounter As Integer = 1
                objDA.Fill(objDS)
                lblRecordCount.Text = CStr(objDS.Tables(0).Rows.Count)
    
                'My record counter loop
                For intCounter = 0 To objDS.Tables(0).Rows.Count - 1
                    lblFrIntCounter.Text = lblFrIntCounter.Text & intNewCounter.ToString
                    intNewCounter += 1
                Next
    
                objDS = Nothing
                objDS = New DataSet()
            End If
    
            objDA.Fill(objDS, CInt(lblCurrIndex.Text), CInt(lblPageSize.Text), "contactUs")
            dblDisplay.DataSource = objDS.Tables(0).DefaultView
            dblDisplay.DataBind()
            objConn.Close()
            PrintStatus()
        End Sub
    What’s the matter with what I’m doing?
    "Ignorance and prejudice and fear walk hand in hand" - 'Witch Hunt', by Rush

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    What is the error?
    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Location
    Phoenix, AZ
    Posts
    22
    "Object reference not set to an instance of an object. " is the error.
    "Ignorance and prejudice and fear walk hand in hand" - 'Witch Hunt', by Rush

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