我如何在页面加载事件中使用它 [英] how i use this in page load event

查看:70
本文介绍了我如何在页面加载事件中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void Page_Load(object sender, EventArgs e)
  {

      if (!IsPostBack)
      {
          MultiView1.ActiveViewIndex = 0;
         gvUserInfo_ItemCommand(gvUserInfo,new ListViewCommandEventArgs());//error
         string str = "SELECT * FROM SetPayout_Master";
          com = new SqlCommand(str, con);
          com.CommandType = CommandType.Text;
          da = new SqlDataAdapter(com);
          DataTable dtstr = new DataTable();
          da.Fill(dtstr);
          if (dtstr.Rows.Count > 0)
          {
              viewSetPayout();

          }
      }
  }





// gvUserInfo是ListView

错误:



方法''​​ListViewCommandEventArgs''没有重载需要''0''参数



//gvUserInfo is ListView
error:

No overload for method ''ListViewCommandEventArgs'' takes ''0'' arguments

推荐答案

这是一个事件处理程序 - 你通常不直接调用事件处理程序,而应该通过事件机制调用它们。



如果你想要要在事件处理程序和页面加载中执行相同的代码,我建议您将代码提取到单独的方法并从两个位置调用它。然后你不需要创建EventArgs,你的问题就会自动消失。
That is an event handler - you do not normally call event handlers directly, they should be called through the events mechanism instead.

If you want to execute the same code in your event handler and your page load, then I would suggest that you extract the code to a separate method and call it from both locations. You then won''t need to create the EventArgs, and your problem will disappear on it''s own.


错误方法没有重载''ListViewCommandEventArgs''需要'' 0''参数清楚地告诉ListViewCommandEventArgs类没有接收0参数的构造函数。意味着ListViewCommandEventArgs构造函数具有您应该提供的参数。

所以你错误地调用了新的ListViewCommandEventArgs()。请查看ListViewCommandEventArgs对象的定义,特别是其构造函数定义。我想那时你了解哪个参数应该与该构造函数一起传递并解决问题。



再次事件处理程序直接调用不是好习惯。您可以编写可重用的函数,并且可以使用适当的参数调用各种事件处理程序。
The error "No overload for method ''ListViewCommandEventArgs'' takes ''0'' arguments" clearly tell that ListViewCommandEventArgs class has no constructor which receive 0 argument. Means ListViewCommandEventArgs constructor has argument(s) which you should supply.
So you wrongly call new ListViewCommandEventArgs(). Please see the definition of ListViewCommandEventArgs object specially its constructor definition. I guess then you understand which parameter should pass with that constructor and solve the problem.

Again event handler directly call is not good practice. You can write reusable function and from various event handler you can call that with appropriate arguments.


这篇关于我如何在页面加载事件中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆