Repeater ItemDataBound FindControl Reference为NULL

时间:2015-09-15 13:50:58

标签: asp.net vb.net repeater

在下面的代码示例中,e.Item.FindControl(" btnSignup")并不是什么,但btn什么都不是。这是为什么?如何在转发器的页脚中设置btnSignup的可见性?

Protected Sub rptParticipants_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles rptParticipants.ItemDataBound

    If e.Item.ItemType = ListItemType.Footer Then 

        Dim btn As New Button           
        btn = CType(e.Item.FindControl("btnSignup"), Button)

        If btn IsNot Nothing Then
            btn.Visible = False
        End If

    End If

End Sub

1 个答案:

答案 0 :(得分:0)

e.Item.FindControl(“btnSignup”)是什么类型的?

我更喜欢这样编码:

If Not (btn Is Nothing) Then
      '...
End If