Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying record # for each record in a datalist

Status
Not open for further replies.

JoeCool32

Programmer
Sep 26, 2002
50
0
0
US
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? [sadeyes]

JJ [peace]

"Ignorance and prejudice and fear walk hand in hand" - Witch Hunt, by Rush
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top