GridView OnRowCreated没有被解雇 - 将VB项目转换为C#

时间:2014-09-15 09:22:47

标签: c# asp.net vb.net gridview user-controls

如果这看起来有点啰嗦,我现在道歉。

我被赋予了将工作VB.Net解决方案重写为C#的任务。原因是有效的,但我不会在这里进入。

我已经完成了重写,但正如预期的那样,我现在遇到了一些障碍。主要1是特定的GridView用户控件(ascx)。这个特定的控件是从另一个项目(类库)创建的,它创建了一个名为EnhancedGridView的gridview控件,增强了分页等,如下所示:

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

这背后的原因是有一个通用的gridview控件,然后可以由其他gridview用户控件使用和定制。 EnhancedGridView dll在我的ascx控件中注册,如下所示:

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

问题在于vb版本在ascx控件中呈现EnhancedGridview控件。 RowCreated事件在EnhancedGridview控件中触发,然后在ascx中触发单独的RowCreated事件(与RowDataBound相同)。但是,在我的C#版本中,只有使用OnRowCreated等在控件中注册了ascx事件,才会触发EnhancedGridview事件。下面是一些代码来说明我的问题:

ascx VB控制OnRowCreated事件(在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#控制OnRowCreated事件(虽然不会通过EnhancedGridView OnRowCreated启动)

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

使用C#版本,我已使用OnRowCreated =&#34; GridView1_RowCreated&#34;将此事件注册到GridView1.RowCreated事件。但是,它仍然没有发射(以及其他事件)。我尝试将GridView转换为普通的GridView(不使用EnhancedGridView)并触发RowCreated事件(以及其他事件),因此我知道它与EnhancedGridView有关,以及它如何与我的ascx控件进行链接。

任何人都可以帮我指出正确的方向吗?

更新

我已经做了一些进一步的调试,似乎只有RowCreated事件无法正常工作。以前它也是RowDataBound。但是,我做了一些改变,并且假设(我知道的坏主意)它仍然会影响这两个事件。但是,在进一步测试时,RowDataBound事件现在被解雇了。这仍然似乎与EnhancedGridView有关,因为它没有RowDataBound事件,但它确实有一个RowCreated事件,它被调用(并且ascx RowCreated事件不被调用)。

1 个答案:

答案 0 :(得分:0)

根据评论中的MSDN,我需要确保调用基类的OnRowCreated方法以确保注册的代理人收到了该事件。所以我只是添加了base.OnRowCreated(e);&#39;进入EnhancedGridView OnRowCreated方法。