我的代码
private void Page_Load(object sender, System.EventArgs e)
{
DataGrid1.AllowPaging = true;
DataGrid1.PagerStyle.Mode = PagerMode.NumericPages;
DataGrid1.PagerStyle.PageButtonCount = 5;
DataGrid1.PageSize = 5;
if (!Page.IsPostBack)
{
DataGrid1.DataBind();
}}
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection MyConnection=new SqlConnection("server=MY-TOMATO\\HJHSQLSERVER;database=Materials;uid=hjh;pwd=911144");
string SelectCommand="select 材料名 from Element";
SqlCommand MyCommand=new SqlCommand(SelectCommand,MyConnection);
MyCommand.Connection.Open();
SqlDataReader dr;
dr=MyCommand.ExecuteReader();
this.DataGrid1.DataSource=dr;
this.DataGrid1.DataBind();
dr.Close();
MyCommand.Connection.Close();
}private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}运行后提示:
c:\inetpub\wwwroot\WebApp\test.aspx.cs(85): “System.EventArgs”并不包含对“NewPageIndex”的定义如果将 DataGrid1.CurrentPageIndex = e.NewPageIndex;
和 DataGrid1.DataBind(); 设为注释后,再运行,点击button1,提示:当 AllowPaging 设置为真并且选定的数据源不实现 ICollection 时,AllowCustomPaging 必须为真,并且 ID 为 DataGrid1 的 DataGrid 必须设置 VirtualItemCount。这是什么意思啊,那位高手指点一下,小弟感激不尽
private void Page_Load(object sender, System.EventArgs e)
{
DataGrid1.AllowPaging = true;
DataGrid1.PagerStyle.Mode = PagerMode.NumericPages;
DataGrid1.PagerStyle.PageButtonCount = 5;
DataGrid1.PageSize = 5;
if (!Page.IsPostBack)
{
DataGrid1.DataBind();
}}
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection MyConnection=new SqlConnection("server=MY-TOMATO\\HJHSQLSERVER;database=Materials;uid=hjh;pwd=911144");
string SelectCommand="select 材料名 from Element";
SqlCommand MyCommand=new SqlCommand(SelectCommand,MyConnection);
MyCommand.Connection.Open();
SqlDataReader dr;
dr=MyCommand.ExecuteReader();
this.DataGrid1.DataSource=dr;
this.DataGrid1.DataBind();
dr.Close();
MyCommand.Connection.Close();
}private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}运行后提示:
c:\inetpub\wwwroot\WebApp\test.aspx.cs(85): “System.EventArgs”并不包含对“NewPageIndex”的定义如果将 DataGrid1.CurrentPageIndex = e.NewPageIndex;
和 DataGrid1.DataBind(); 设为注释后,再运行,点击button1,提示:当 AllowPaging 设置为真并且选定的数据源不实现 ICollection 时,AllowCustomPaging 必须为真,并且 ID 为 DataGrid1 的 DataGrid 必须设置 VirtualItemCount。这是什么意思啊,那位高手指点一下,小弟感激不尽
不是吧
我记得应该是PageIndexChanged
SelectedIndexChanged是DataGrid的选择列的事件