Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated 
        Dim RecoderCount As Integer = Me.GridView1.Rows.Count 
        If e.Row.RowType = DataControlRowType.Pager Then 
            e.Row.Controls.Clear() 
            Dim tc As New TableCell() 
            Dim txtNewPageIndex As New System.Web.UI.WebControls.TextBox() 
            txtNewPageIndex.Width = 20 
            tc.Controls.Add(txtNewPageIndex
            e.Row.Controls.Add(tc) 
        End If 
    End Sub 
请问,我怎么获得这个txtNewPageIndex控件? CType(GridView1.BottomPagerRow.FindControl("txtNewPageIndex"), System.Web.UI.WebControls.TextBox) 
这样写不对,找不到这个控件。

解决方案 »

  1.   

    lz是要在这个事件外获得这个控件吗?至少应该定义这个控件的ID,然后CType(GridView1.BottomPagerRow.FindControl("定义的控件ID"), System.Web.UI.WebControls.TextBox)这样来找这个控件,lz试试看行不行~
      

  2.   

    谢谢你,我试了下对了。
    Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated 
            Dim RecoderCount As Integer = Me.GridView1.Rows.Count 
            If e.Row.RowType = DataControlRowType.Pager Then 
                e.Row.Controls.Clear() 
                Dim tc As New TableCell() 
                Dim txtNewPageIndex As New System.Web.UI.WebControls.TextBox() 
                txtNewPageIndex.Width = 20 
                txtNewPageIndex.id="txtNewPageIndex1"   加了句这个,        
                tc.Controls.Add(txtNewPageIndex) 
                e.Row.Controls.Add(tc) 
            End If 
        End Sub 原来我老把变量名txtNewPageIndex认为就是那控件的id
    CType(GridView1.BottomPagerRow.FindControl("txtNewPageIndex1"), System.Web.UI.WebControls.TextBox)