当前位置 : 主页 > 网络编程 > ASP >

asp.net – 以编程方式从GridView添加和删除事件

来源:互联网 收集:自由互联 发布时间:2021-06-24
我有一个如下的GridView: asp:GridView ID="Results" runat="server" OnRowDataBound="Results_RowDataBound" EmptyDataTemplateNo results found/EmptyDataTemplate/asp:GridViewProtected Sub Results_RowDataBound(ByVal sender As Object, ByVal
我有一个如下的GridView:

<asp:GridView ID="Results" runat="server" OnRowDataBound="Results_RowDataBound">
    <EmptyDataTemplate>No results found</EmptyDataTemplate>
</asp:GridView>



Protected Sub Results_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
            'do a bunch of work here
End Sub

根据用户输入,有时我想要触发OnRowDataBound事件,有时我不想.

有没有办法以编程方式打开或关闭事件?

以下是编程为 add and remove events in VB.NET的示例代码:

If CheckBox1.Checked Then
    AddHandler Results.RowDataBound, AddressOf Results_RowDataBound
Else
    RemoveHandler Results.RowDataBound, AddressOf Results_RowDataBound
End If
网友评论