日期:2014-05-19  浏览次数:21143 次

这在给定的上下文中无效
新手,所以在网上找些程序来试,出现错误
报错:
“ASP.printbower2_aspx.MyDataGrid_Page(object,   System.Web.UI.WebControls.DataGridPageChangedEventArgs)”是一个“方法”,这在给定的上下文中无效

源错误:

 

行   60:           void   BindGrid()
行   61:           {
行   62:                   MyDataGrid_Page.DataSource   =   CreateDataSource();
行   63:                   MyDataGrid_Page.DataBind();
行   64:                   ShowStats();
 
他的CreateDataSource是这样写的:
        ICollection   CreateDataSource()
        {
                string   strConnection   =   "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA   SOURCE= "   +   Server.MapPath( "local.mdb ")   +   "; ";
                string   strSQL   =   "SELECT   *   FROM   MOBILE_CALL_TICKET_ZRY ";
                OleDbConnection   MyConnection   =   new   OleDbConnection(strConnection);
                OleDbDataAdapter   MyDataSetCommand   =   new   OleDbDataAdapter(strSQL,   MyConnection);
                DataSet   ds   =   new   DataSet();
                MyDataSetCommand.Fill(ds,   "admin_enter ");
                return   ds.Tables[ "admin_enter "].DefaultView;
          }
我不明白为什么在上下文中无效,请大家指教。

补充一下,上面的CreateDataSource()是我改过的,他用的是SQL,我要用Access,可能是我改错吧,但我不知道错在哪,他原来的程序是这样的
ICollection   CreateDataSource()
{
/*
读取数据库的信息,获得DataView
*/
SQLConnection   MyConnection   =   new   SQLConnection( "server=localhost;uid=sa;pwd=123456;database=aspcn ");
SQLDataSetCommand   MyDataSetCommand   =   new   SQLDataSetCommand( "select   *   from   admin_enter   order   by   Enter_Time   desc ",MyConnection);
DataSet   ds=   new   DataSet();
MyDataSetCommand.FillDataSet(ds, "admin_enter ");
return   ds.Tables[ "admin_enter "].DefaultView;
}



------解决方案--------------------
缺少引用
------解决方案--------------------
MyDataGrid_Page 是一个翻页事件,有可能你事件不匹配,删除掉,重新在前台进行事件添加

------解决方案--------------------
MyDataGrid_Page.DataSource = CreateDataSource();
------------------------------------------------
MyDataGrid_Page这是一个事件处理函数把
MyDataGrid.DataSource = CreateDataSource();
MyDataGrid.DataBind();
------解决方案--------------------
在后台注册事件了吗?注册的事件处理程序是否是MyDataGrid_Page