同一个页面中,不用public就行
其实写成 void DataFiller() 都行的.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data .SqlClient;
namespace tiaoshi
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dg;
private void InitializeComponent()
{
this.dg.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dg_PageIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
DataFiller();
}
}
void DataFiller()
{
SqlConnection sqlcon=new SqlConnection("Data Source=localhost;uid=sa;pwd=admin;Initial Catalog=Northwind");
String strSQL="select ProductID,ProductName From Products Order By ProductID";
SqlDataAdapter sqldr=new SqlDataAdapter(strSQL,sqlcon);
DataSet ds=new DataSet();
sqldr.Fill(ds,"dtProducts");
dg.PagerStyle.NextPageText="Next";
dg.PagerStyle.PrevPageText="Previous";
dg.DataSource=ds.Tables["dtProducts"];
dg.DataBind();
sqlcon.Close();
}
private void dg_PageIndexChanged(object source,System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.dg.CurrentPageIndex=e.NewPageIndex;
DataFiller();
}
}
}
我将程序该成这样,可还是提示这样的错误 CS0122: 不可访问“tiaoshi.WebForm1.dg_PageIndexChanged(object, System.Web.UI.WebControls.DataGridPageChangedEventArgs)”,因为它受保护级别限制
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data .SqlClient;
namespace tiaoshi
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dg;
private void InitializeComponent()
{
this.dg.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dg_PageIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
DataFiller();
}
}
void DataFiller()
{
SqlConnection sqlcon=new SqlConnection("Data Source=localhost;uid=sa;pwd=admin;Initial Catalog=Northwind");
String strSQL="select ProductID,ProductName From Products Order By ProductID";
SqlDataAdapter sqldr=new SqlDataAdapter(strSQL,sqlcon);
DataSet ds=new DataSet();
sqldr.Fill(ds,"dtProducts");
dg.PagerStyle.NextPageText="Next";
dg.PagerStyle.PrevPageText="Previous";
dg.DataSource=ds.Tables["dtProducts"];
dg.DataBind();
sqlcon.Close();
}
private void dg_PageIndexChanged(object source,System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.dg.CurrentPageIndex=e.NewPageIndex;
DataFiller();
}
}
}
我将程序该成这样,可还是提示这样的错误 CS0122: 不可访问“tiaoshi.WebForm1.dg_PageIndexChanged(object, System.Web.UI.WebControls.DataGridPageChangedEventArgs)”,因为它受保护级别限制
把我标红的那行加上private
我试过了,在void DataFiller() 前加了private,结果还是同样的错误,为什么呢.
麻烦了.
我试过了,在void DataFiller() 前加了private,结果还是同样的错误,为什么呢.
麻烦了.
从代码上看,我找不到任何有问题的地方,茫然中………
你看看是不是IIS的什么设置问题呢