views:

205

answers:

2

I've got a GridView like below:

<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

Based upon user input, sometimes I want the OnRowDataBound event to fire, sometimes I don't.

Is there a way to programatically turn the event on or off?

+1  A: 

Wouldn't it be easier to add an if inside your event handler and ignore the event when you don't need it?

chris
+1  A: 

Here is a sample code to add and remove events in VB.NET programatically :

If CheckBox1.Checked Then
    AddHandler Results.RowDataBound, AddressOf Results_RowDataBound
Else
    RemoveHandler Results.RowDataBound, AddressOf Results_RowDataBound
End If
Canavar