将 OnRowDataBound 添加到 GridView 后页面为空
Page is empty after adding OnRowDataBound to a GridView
我向 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
aspx 是代码隐藏页面的子项。因此,如果您以声明方式添加事件处理程序,则处理程序方法必须至少为 Protected
。
Protected Sub itemGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
End Sub
另一种选择是在代码隐藏中添加处理程序,使用 Handles
或 AddHandler
。
我向 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
aspx 是代码隐藏页面的子项。因此,如果您以声明方式添加事件处理程序,则处理程序方法必须至少为 Protected
。
Protected Sub itemGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
End Sub
另一种选择是在代码隐藏中添加处理程序,使用 Handles
或 AddHandler
。