我想通过使用接口来执行 Class2(和其他)类中的
ShowControls()
方法。 Show Controls() 方法包含一个 switch 语句,该语句在 GridView 数据绑定期间根据其行索引确定显示或隐藏 GridView 项目模板中的各种控件(其中许多是自定义用户控件)。当我从 Class2 调用该方法时,我收到此错误消息:CS1503 Argument 1:无法从“System.EventArgs”转换为“System.Web.UI.WebControls.GridViewRowEventArgs”。这让我很困惑,因为我在方法中明确指定了参数 GridViewRowEventArgs
。
有人可以帮我正确设置吗?也许我无法在界面中引用 Web 控件?我在
I_BuildGridView
和 BuildControl
中具体引用了以下 using 语句:
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 参考来构建界面
经过思考,我意识到 Page_Load() 事件不是调用 ShowControls() 方法的地方,而是 GridViews 的 RowDataBound 事件 - 因为对参数的引用可以从那里获得,但在Page_Load() 事件。