locked
Gridview - scroll down list to current date RRS feed

  • Question

  • User35285974 posted

    I've a gridview on a page, one of the field is the date, the following code is written in VB as code behind, basically when the page is loaded the gridview scrolls down until the record with the current date or as close to it as possible and then highlights the row in yellow. This is fine when viewed in IE or Chrome on a desktop PC, but when viewed on an Iphone using Safari the only part of the process that works is the line highlighted in Yellow, it won't scroll down automatically. I can detect what is looking at the page using code behind so writing a mobile phone page only version isn't a problem. Does anyone know of an alternative way of achieving this ?

    ## Edit ## It turns out this isn't a Safari issue, I've just downloaded Google Chrome onto my Iphone X and I get the same problem, I've also noticed on the mobile phone version of the page the vertical scroll bar is missing.

    @@@@@ VB Code Behind @@@@@
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    dt = GetData()
    gvCustomers.DataSource = dt
    gvCustomers.DataBind()
    For Each row As GridViewRow In gvCustomers.Rows
    If Not bolRowFound Then
    If row.Visible Then
    If row.Cells(GetIndexForColumn(gvCustomers, "Date")).Text.Trim = Format(Now, "dd MMM yyyy") Then ' "26/03/2015 10:01:00" Then
    row.BackColor = Drawing.Color.Yellow
    row.Cells(0).Focus()
    bolRowFound = True
    rowFinder = row.RowIndex
    End If
    End If
    ElseIf bolRowFound Then
    tmpCounter += 1
    row.Cells(0).Focus()
    If tmpCounter = 10 Then
    Exit For
    End If
    End If
    Next
    End Sub

    Private Function GetIndexForColumn(ByVal gv As GridView, ByVal colName As String) As Integer
    For j = 0 To gv.HeaderRow.Cells.Count - 1
    If UCase(gv.HeaderRow.Cells(j).Text) = UCase(colName) Then
    Return j
    End If
    Next
    Return 0
    End Function

     

    Wednesday, September 25, 2019 7:52 AM

All replies

  • User288213138 posted

    Hi Meridian2002,

    According to you description, i can't reproduce your question.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    dt = GetData()
    gvCustomers.DataSource = dt
    gvCustomers.DataBind()
    For Each row As GridViewRow In gvCustomers.Rows
    If Not bolRowFound Then
    If row.Visible Then
    If row.Cells(GetIndexForColumn(gvCustomers, "Date")).Text.Trim = Format(Now, "dd MMM yyyy") Then ' "26/03/2015 10:01:00" Then
    row.BackColor = Drawing.Color.Yellow
    row.Cells(0).Focus()
    bolRowFound = True
    rowFinder = row.RowIndex
    End If
    End If
    ElseIf bolRowFound Then
    tmpCounter += 1
    row.Cells(0).Focus()
    If tmpCounter = 10 Then
    Exit For
    End If
    End If
    Next
    End Sub

    Private Function GetIndexForColumn(ByVal gv As GridView, ByVal colName As String) As Integer
    For j = 0 To gv.HeaderRow.Cells.Count - 1
    If UCase(gv.HeaderRow.Cells(j).Text) = UCase(colName) Then
    Return j
    End If
    Next
    Return 0
    End Function

    Can you tell me does this code have anything to do with your scroll down automatically?

    Meridian2002

    it won't scroll down automatically

    Can you show me how did you achieve it? by jquery or in the code behind?

    Please post more code about your question.

    Best regards,

    Sam

    Thursday, September 26, 2019 2:52 AM