Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.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_Delegates - Fatal编程技术网

C# 使用事件和委托的灵活性

C# 使用事件和委托的灵活性,c#,asp.net,gridview,user-controls,delegates,C#,Asp.net,Gridview,User Controls,Delegates,我试图从用户控件调用父页面中的方法: 用户控制: public delegate void CallParent(); public event CallParent BindData; protected void LoadDataPageWise(int iCurrentPage) { iPageIndex1 = iCurrentPage - 1; BindData(); // Thi

我试图从用户控件调用父页面中的方法:

用户控制:

    public delegate void CallParent();
    public event CallParent BindData;

   protected void LoadDataPageWise(int iCurrentPage)
        {
            iPageIndex1 = iCurrentPage - 1;
            BindData();           // This should trigger method in parent page
            DisplayPageNumber();
        }
父页面:

如何在父页面的页面加载中附加该代理

   public void BindGridRecords()
        {
            grdPages.PageIndex = rptPager.iPageIndex1;
            grdPages.DataBind();
            Session["PageIndex"] = grdPages.PageIndex;
        }

将此行添加到父页面的加载方法:


rptPager.BindData+=this.BindGridRecords

我想你可以在控件上使用
这个.Page
。您可以将该属性强制转换为实际页面对象,然后在该对象上调用所需的任何方法,只要该对象是可访问的。

假设
grdPages
是用户控件的名称。如果不是,则将用户控件的名称放在那里。