Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何处理用户控件网格视图的事件?_C#_Asp.net_Gridview_User Controls - Fatal编程技术网

C# 如何处理用户控件网格视图的事件?

C# 如何处理用户控件网格视图的事件?,c#,asp.net,gridview,user-controls,C#,Asp.net,Gridview,User Controls,我有一个用户控件作为网格视图。 我正在动态添加它…我已经为数据源创建了方法,但我无法使用网格视图的其他事件,如“行数据绑定”等 我在网上看过代码,上面写着创建委托并添加以下内容 protected void Simple_DGV_RowDataBound(object sender, GridViewRowEventArgs e) { OnRowDataBound(e); } 但是我在这里得到一个错误,即当前上下文中不存在OnRowDataBound的名称 有人能帮我访问父页面中用户控件

我有一个用户控件作为网格视图。 我正在动态添加它…我已经为数据源创建了方法,但我无法使用网格视图的其他事件,如“行数据绑定”

我在网上看过代码,上面写着创建委托并添加以下内容

protected void Simple_DGV_RowDataBound(object sender, GridViewRowEventArgs e)   
{
OnRowDataBound(e);
}
但是我在这里得到一个错误,即当前上下文中不存在OnRowDataBound的名称

有人能帮我访问父页面中用户控件网格视图的事件吗

编辑:


这是我的ascx页面…我想在多个位置(运行时)使用此网格视图,因此我创建了一个用户控件。。。 基本上,我想从我的代码后面调用这个用户控件,然后使用它的rowdatabound,我想将数据绑定到gridview

我在网站上看到它说使用事件冒泡…但我不知道如何实现这一点

那么你能帮我解决这个问题吗..这样我就可以像我一样正常使用rowdatabound了


thnx预先

我已经在本地创建了一个项目,这很好

我有一个名为TestUserControl.ascx的控件。我在设计模式中将GridView控件拖到用户控件上,并将其称为“grdControlsGrid”

这就产生了下面的标记

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestUserControl.ascx.cs" Inherits="TestASPNet.TestUserControl" %>
<asp:GridView ID="grdControlsGrid" runat="server">
</asp:GridView>
由于某些原因,当通过标记自动连接时,您会得到事件“OnRowDataBound”。。但是当在代码隐藏中手动完成时,您会得到“RowDataBound”。我猜他们是同一个人。。但也许其他人可以解释这一点


希望有帮助。

OnRowDataBound在哪里声明?如果您是从一个示例中获取这一点,那么您需要该方法的代码。否则,只需将需要执行的任何操作的代码放入简单的RowDataBound方法本身。我在这里看到了代码,实际上我想访问创建的gridview的RowDataBound..但由于我的grid view是用户控件,我需要定义RowDataBound…我该如何做?如果您查看步骤8。在代码项目中,您可以看到所需方法的实现!另外,您的意思是您有一个包含GridView的usercontrol吗?或者你的用户控件是一个GridView,但是你从GridView继承来创建你自己的。编辑了我的问题…希望现在它是清晰的是的,我也在网上搜索…然后幸运的是,刚才得到了逻辑。如果有人想动态加载控件,那么他们应该使用替代方法,因为我们不会创建硬编码控件。谢谢你的邀请efforts@rk-没问题。很高兴你找到了解决办法。干杯
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestUserControl.ascx.cs" Inherits="TestASPNet.TestUserControl" %>
<asp:GridView ID="grdControlsGrid" runat="server">
</asp:GridView>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestUserControl.ascx.cs" Inherits="TestASPNet.TestUserControl" %>
<asp:GridView ID="grdControlsGrid" runat="server" OnRowDataBound="grdControlsGrid_OnRowDataBound">
</asp:GridView>
 public partial class TestUserControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Manually Add event handler
            grdControlsGrid.RowDataBound += GrdControlsGrid_RowDataBound;
        }

        private void GrdControlsGrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //Manually bound event
        }

        protected void grdControlsGrid_OnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            //Auto wired event
        }
    }