新手,所以在网上找些程序来试,出现错误
报错:
“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;
}

解决方案 »

  1.   

    jerryfos(想飞)回说:这个错误和你的CreateDataSource()无关,你看一下你的DataGrid“属性”-》“方法”里PageIndexChanged有没有对应上,我觉得是控件的响应事件句柄没有对应上。我还是不清楚错在哪里,所以把Datagrid的代码也贴出来
    <ASP:DataGrid id="MyDataGrid" runat="server"
    AllowPaging="True"
    PageSize="10"
    PagerStyle-Mode="NumericPages"
    PagerStyle-HorizontalAlign="Right"
    OnPageIndexChanged="MyDataGrid_Page"
    BorderColor="black"
    BorderWidth="1"
    GridLines="Both"
    CellPadding="3"
    CellSpacing="0"
    Font-Name="Verdana"
    Font-Size="8pt"
    HeaderStyle-BackColor="#aaaadd"
    AlternatingItemStyle-BackColor="#eeeeee"
    AutoGenerateColumns="false" >
        <Columns>
            <asp:BoundColumn DataField="编号 HeaderText="编号" />
            <asp:BoundColumn DataField="CALLED_NBR" HeaderText="手机号码" />
            <asp:BoundColumn DataField="CALLED_AREA_COD" HeaderText="被叫号码区号" 
                 ItemStyle-HorizontalAlign="right"/>
            <asp:BoundColumn DataField="CALLING_NBR" HeaderText="被叫号码" 
                 ItemStyle-HorizontalAlign="right"/>
            <asp:BoundColumn DataField="START_TIME" HeaderText="通话时间" 
                 ItemStyle-HorizontalAlign="right"/>
            <asp:BoundColumn DataField="ACCT_ITEM_TYPE" HeaderText="通话记录" 
                 ItemStyle-HorizontalAlign="right"/>
            <asp:BoundColumn DataField="CHARGE" HeaderText="通话费用" 
                 ItemStyle-HorizontalAlign="right"/>
            <asp:BoundColumn DataField="DURATION" HeaderText="持续时间" 
                 ItemStyle-HorizontalAlign="right"/>
        </Columns>
        </ASP:DataGrid>
      

  2.   

    缺少引用?可否说得详细点,谢谢。
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SQL" %>
    我改了
    <%@ Page Language="C#" Debug="true" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Web.Security " %>
    <%@ Import Namespace="System.Data.OleDb" %> 
      

  3.   

    MyDataGrid_Page 是一个翻页事件,有可能你事件不匹配,删除掉,重新在前台进行事件添加
      

  4.   

    MyDataGrid_Page.DataSource = CreateDataSource();
    ------------------------------------------------
    MyDataGrid_Page这是一个事件处理函数把
    MyDataGrid.DataSource = CreateDataSource();
    MyDataGrid.DataBind();
      

  5.   

    在后台注册事件了吗?注册的事件处理程序是否是MyDataGrid_Page
      

  6.   

    结贴,给分,CreateDataSource();整个不要了。