Vb.net System.Web.UI.Control转换为System.Windows.Form

Vb.net System.Web.UI.Control转换为System.Windows.Form,vb.net,gridview,Vb.net,Gridview,我有以下代码,到目前为止运行正常,突然出现此错误('System.Web.UI.Control'无法转换为'System.Windows.Forms.Label') 在演示之前弹出。如能迅速提供帮助,将不胜感激。谢谢 Private Sub InitialiseGridViewPagerRow(ByVal gridView As GridView) Dim gridViewRow As GridViewRow = gridView.BottomPagerRow I

我有以下代码,到目前为止运行正常,突然出现此错误('System.Web.UI.Control'无法转换为'System.Windows.Forms.Label') 在演示之前弹出。如能迅速提供帮助,将不胜感激。谢谢

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
Private子初始值为gridView页面箭头(ByVal gridView作为gridView)
将gridViewRow调整为gridViewRow=gridView.BottomPagerRow
如果(Not(gridViewRow)为Nothing),则
如果(gridView.PageIndex=0),则
将firstPageImageButton设置为LinkButton=CType(gridViewRow.FindControl(gridView.ID&“First”),LinkButton)
将previousPageImageButton设置为LinkButton=CType(gridViewRow.FindControl(gridView.ID&“Previous”),LinkButton)
如果((Not(firstPageImageButton)为Nothing)和(Not(previousPageImageButton)为Nothing),则
firstPageImageButton.Enabled=False
firstPageImageButton.CssClass=“firstdisabled”
previousPageImageButton.Enabled=False
previousPageImageButton.CssClass=“previousdisabled”
如果结束
ElseIf((gridView.PageIndex+1)=gridView.PageCount)然后
Dim lastPageImageButton As LinkButton=CType(gridViewRow.FindControl(gridView.ID&“Last”),LinkButton)
Dim nextPageImageButton As LinkButton=CType(gridViewRow.FindControl(gridView.ID&“下一步”),LinkButton)
如果((Not(lastPageImageButton)为空)并且(Not(nextPageImageButton)为空),则
lastPageImageButton.Enabled=False
lastPageImageButton.CssClass=“lastdisabled”
nextPageImageButton.Enabled=False
nextPageImageButton.CssClass=“nextdisabled”
如果结束
其他的
将firstPageImageButton设置为LinkButton=CType(gridViewRow.FindControl(gridView.ID&“First”),LinkButton)
将previousPageImageButton设置为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&“下一步”),LinkButton)
如果((Not(firstPageImageButton)为Nothing)和((Not(lastPageImageButton)为Nothing)和((Not(previousPageImageButton)为Nothing)和((Not(nextPageImageButton)为Nothing)),则
firstPageImageButton.Enabled=True
lastPageImageButton.Enabled=True
nextPageImageButton.Enabled=True
previousPageImageButton.Enabled=True
如果结束
如果结束
Dim pageNumberDropDownList作为DropDownList=CType(gridViewRow.FindControl(gridView.ID&“ddlPgNo”),DropDownList
'错误仅出现在下一行
Dim pageCountLabel作为System.Web.UI.WebControl.Label=CType(gridViewRow.FindControl(gridView.ID和“PgCnt”),标签)
如果((Not(pageNumberDropDownList)为Nothing)和(Not(pageCountLabel)为Nothing)),则
尺寸i为整数=0
执行时(i
通过评论解决了该问题

Imports System.Windows.Forms

您使用的是
标签
,它似乎将其解释为
System.Windows.Forms.Label
。这意味着您将
System.Windows.Forms
名称空间导入到某个地方,要么在该代码文件的头部,要么在项目本身中。我想说的是最喜欢后者,你可以在项目属性的参考页面上查看。谢谢@jmcilhinney,我评论了import System.Windows.Forms,它现在工作正常