100分求助!!!极度郁闷的错误..不知道错在哪里..关于DATAGRID分页的
想完成一个
"点击button后查找出数据表U中后缀如@163.com的电子邮件.并且以分页的形式显示在DATAGRID上"
的功能
程序如下.TextBox1.Text是输入163.com或者sina.com.cn
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
private void Button1_Click(object sender, System.EventArgs e)
{
BindGrid();
}
private void BindGrid()
{
DataSet ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter();
this.sqlConnection1.Open();
this.sqlCommand1.CommandText="select * from U where EMAIL like '%@"+TextBox1.Text+"'";
da.SelectCommand=this.sqlCommand1;
da.Fill(ds,"U");
this.DataGrid1.DataSource=ds;
this.DataGrid1.DataBind();
this.sqlConnection1.Close();
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindGrid();
DataGrid1.DataBind();
}
}
现在的情况是分页功能顺利实现.
但是出现郁闷的问题是:
我的表里面有10条@163.com和1条@sina.com.cn为后缀的邮件记录.
我查询@163.com.查出来10条分页记录后后对DATAGRID进行翻页查看操作!!!!
然后我再查询@sina.com.cn时,出现了以下错误!!!:
无效的 CurrentPageIndex 值。它必须大于等于 0 且小于 PageCount
请问这是怎么回事,程序应该是对的呀,为什么会有冲突...