请问一下,"因为它受保护级别限制,",是指什么意思,那该改什么文件或者该做什么呢
请问一下,"因为它受保护级别限制,",是指什么意思,那该改什么文件或者该做什么呢
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
DataFiller();
}
}
private void DataFiller()
{
SqlConnection sqlcon=new SqlConnection("Data Source=localhost;uid=sa;pwd=admin;Initial Catalog=Northwind");
//SqlCommand sqlcom=new SqlCommand("select * from Products",sqlcon);
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.Open();
//dg.DataSource=sqlcom.ExecuteReader();
//dg.DataBind();
sqlcon.Close();
}
private void GridPageChange(object s,DataGridPageChangedEventArgs e)
{
dg.CurrentPageIndex=e.NewPageIndex;
DataFiller();
}
}
}
这是程序代码,我将函数该成public,结果页面什么也没有,也没提示错误,这是为什么呢
麻烦各位了,谢谢
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)”,因为它受保护级别限制
我试过了,在void DataFiller() 前加了private,结果还是同样的错误,为什么呢.
麻烦了.
麻烦各位了,谢谢,