简体   繁体   中英

GridView OnRowCreated not getting fired - converted VB project to C#

I apologise now if this seems a bit long winded.

I've been given the task of rewriting a working VB.Net solution into C#. The reason is valid for this but I won't go into it here.

I've completed the rewrite, but as expected I'm now hitting a few snags. The main 1 being a particular GridView user control (ascx). This particular control is created from another project (class library) that creates a gridview control called EnhancedGridView with enhanced paging etc like this:

namespace EnhancedGridView
{
    public class GridView : System.Web.UI.WebControls.GridView
    {
        //stuff
    }
}

The reason behind this is to have 1 generic gridview control that can then be used and tailored by other gridview user controls. The EnhancedGridView dll is registered in my ascx control like this:

<%@ Register Assembly="EnhancedGridView" Namespace="EnhancedGridView" TagPrefix="cc1" %>

The problem lies in that the vb version renders the EnhancedGridview control in the ascx control. The RowCreated event is fired in the EnhancedGridview control and then the separate RowCreated event is fired in the ascx (same with the RowDataBound). However, in my C# version only the EnhancedGridview events get fired despite having the ascx events being registered in the control using the OnRowCreated etc. Below is some code to illustrate my issue:

ascx VB control OnRowCreated event (fires, after EnhancedGridView OnRowCreated):

Protected Sub GridView1_RowCreated(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated

'Do stuff

End Sub

ascx C# control OnRowCreated event (doesn't fire though EnhancedGridView OnRowCreated does)

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
    //Do stuff
}

With the C# version I've registered this event to the GridView1.RowCreated event using OnRowCreated="GridView1_RowCreated". However, it still doesn't fire (along with other events). I tried turning the GridView into a normal GridView (not using EnhancedGridView) and the RowCreated event (and others) fired, so I know it's something to do with the EnhancedGridView and how it's linking with my ascx control.

Can anyone help point me in the right direction?

UPDATE

I've done some further debugging and it seems to be ONLY the RowCreated event that's not working. Previously it was also the RowDataBound as well. However, I'd made several changes and had assumed (bad idea I know) that it would still be impacting both events. However, on further testing the RowDataBound event is now getting fired. This still seems to be related to EnhancedGridView as this has no RowDataBound event, but it does have a RowCreated event, which gets called (and the ascx RowCreated event isn't called).

According to MSDN in the remarks, I needed to ensure I called the base class's OnRowCreated method to ensure registered delegates received the event. So I simply added 'base.OnRowCreated(e);' into the EnhancedGridView OnRowCreated method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM