无法实现接口

时间:2018-05-11 18:51:04

标签: .net c#-4.0 visual-studio-2017

我想通过使用接口在Class2(和其他)类中执行ShowControls()方法。 Show Controls()方法包含一个开关语句,用于确定在GridView数据绑定期间根据GridView数据项的行索引显示或隐藏GridView项目模板中的各种控件(其中许多是自定义用户控件)。当我从Class2调用该方法时,我收到此错误消息: CS1503参数1:无法转换为' System.EventArgs'到' System.Web.UI.WebControls.GridViewRowEventArgs' 。这让我感到困惑,因为我在方法中明确指定了参数GridViewRowEventArgs

有人可以帮我正确设置吗?也许我无法在界面中引用Web控件?我在I_BuildGridViewBuildControl中使用语句特别引用了以下内容:

using System.Web; 
using System.Web.UI;
using System.Web.UI.WebControls;

以下是我如何设置界面:

public interface I_BuildGridView
    {
        void ShowControls(GridViewRowEventArgs e);

    }

public class BuildControls: I_BuildGridView 
    {
      public void ShowControls(GridViewRowEventArgs e)
      {//switch statement here -it's very long so left out here…}
    }  

public partial class Class2 : System.Web.UI.Page
    {     
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            { 
                 //Call interface here
                 I_BuildGridView oShow = new BuildControls();
                oShow.ShowControls(e);//<--error here CS1503 red sqiggly under the e
            }

仅供参考:我使用this引用来构建接口

1 个答案:

答案 0 :(得分:0)

我考虑过删除这个问题,但会由主持人自行决定。在考虑之后,我意识到Page_Load()事件不是调用ShowControls()方法的地方,但是GridViews的RowDataBound事件是 - 因为参数的引用可以从那里获得而在Page_Load中还不知道()事件。至少这是我的推理。如果我错了,请告诉我。