saadasharif
saadasharif

Reputation: 80

System.Web.UI.Control converting to System.Windows.Form

I have the following code, it was working fine until now and out of the blue this error ('System.Web.UI.Control' cannot be converted to 'System.Windows.Forms.Label) pops up just before the demo. Quick help would be highly appreciated. Thanks

Private Sub InitialiseGridViewPagerRow(ByVal gridView As GridView)
        Dim gridViewRow As GridViewRow = gridView.BottomPagerRow
        If (Not (gridViewRow) Is Nothing) Then
            If (gridView.PageIndex = 0) Then


                Dim firstPageImageButton As LinkButton = CType(gridViewRow.FindControl(gridView.ID & "First"), LinkButton)
                Dim previousPageImageButton As LinkButton = CType(gridViewRow.FindControl(gridView.ID & "Previous"), LinkButton)
                If ((Not (firstPageImageButton) Is Nothing) AndAlso (Not (previousPageImageButton) Is Nothing)) Then
                    firstPageImageButton.Enabled = False
                    firstPageImageButton.CssClass = "firstdisabled"
                    previousPageImageButton.Enabled = False
                    previousPageImageButton.CssClass = "previousdisabled"
                End If
            ElseIf ((gridView.PageIndex + 1) = gridView.PageCount) Then

                Dim lastPageImageButton As LinkButton = CType(gridViewRow.FindControl(gridView.ID & "Last"), LinkButton)
                Dim nextPageImageButton As LinkButton = CType(gridViewRow.FindControl(gridView.ID & "Next"), LinkButton)
                If ((Not (lastPageImageButton) Is Nothing) AndAlso (Not (nextPageImageButton) Is Nothing)) Then
                    lastPageImageButton.Enabled = False
                    lastPageImageButton.CssClass = "lastdisabled"
                    nextPageImageButton.Enabled = False
                    nextPageImageButton.CssClass = "nextdisabled"
                End If
            Else

                Dim firstPageImageButton As LinkButton = CType(gridViewRow.FindControl(gridView.ID & "First"), LinkButton)
                Dim previousPageImageButton As LinkButton = CType(gridViewRow.FindControl(gridView.ID & "Previous"), LinkButton)
                Dim lastPageImageButton As LinkButton = CType(gridViewRow.FindControl(gridView.ID & "Last"), LinkButton)
                Dim nextPageImageButton As LinkButton = CType(gridViewRow.FindControl(gridView.ID & "Next"), LinkButton)

                If ((Not (firstPageImageButton) Is Nothing) AndAlso ((Not (lastPageImageButton) Is Nothing) AndAlso ((Not (previousPageImageButton) Is Nothing) AndAlso (Not (nextPageImageButton) Is Nothing)))) Then
                    firstPageImageButton.Enabled = True
                    lastPageImageButton.Enabled = True
                    nextPageImageButton.Enabled = True
                    previousPageImageButton.Enabled = True

                End If
            End If

            Dim pageNumberDropDownList As DropDownList = CType(gridViewRow.FindControl(gridView.ID & "ddlPgNo"), DropDownList)
'Error is only on the following line
            Dim pageCountLabel As System.Web.UI.WebControls.Label = CType(gridViewRow.FindControl(gridView.ID & "PgCnt"), Label)

            If ((Not (pageNumberDropDownList) Is Nothing) AndAlso (Not (pageCountLabel) Is Nothing)) Then
                Dim i As Integer = 0
                Do While (i < gridView.PageCount)
                    Dim page As Integer = (i + 1)
                    pageNumberDropDownList.Items.Add(New ListItem(page.ToString, i.ToString))
                    i = (i + 1)
                Loop
                pageNumberDropDownList.SelectedIndex = gridView.PageIndex
                pageCountLabel.Text = gridView.PageCount.ToString

            End If
        End If
    End Sub

Upvotes: 0

Views: 1935

Answers (1)

saadasharif
saadasharif

Reputation: 80

Issue was resolved by commenting

Imports System.Windows.Forms

Upvotes: 1

Related Questions