将OnRowDataBound添加到GridView后页面为空

时间:2018-12-13 15:15:11

标签: vb.net gridview webforms

我在GridView的OnRowDataBound事件中添加了一个处理程序,此后整个页面及其页面源都是空白。即使处理程序方法为空,也会发生相同的情况。怎么了?

 <asp:GridView ID="itemGridView" 
    runat="server" 
    AutoGenerateColumns="false" 
    DataKeyNames="ItemID" 
    OnRowDataBound="itemGridView_RowDataBound"
    CssClass="table table-striped table-hover table-responsive" 
    BorderStyle="None"
    GridLines="None"
    AllowPaging="True">

 Private Sub itemGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
End Sub

1 个答案:

答案 0 :(得分:0)

aspx是代码隐藏页面的子代。因此,如果以声明方式添加事件处理程序,则处理程序方法必须至少为Protected

Protected Sub itemGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

End Sub

另一种选择是使用HandlesAddHandler在后​​面的代码中添加处理程序。