高分征求:datagrid下弄得自动分页与查询会冲突,如何解决??

来源:百度知道 编辑:UC知道 时间:2024/06/10 02:05:10
要快!!谢谢谢谢大家群策群力,这问题对高手来说很容易的!!
查询事件
protected void Buttoncx1_Click(object sender, EventArgs e)
{

SqlConnection cn = new SqlConnection("Data Source=XIAHAN-821fe4j9;Integrated Security =true;Initial Catalog=RealEstate");
String strSQL = "select * from RealEstate where charindex('" + TextBox12.Text + "',DistinctArea)!=0";
SqlCommand cm = new SqlCommand(strSQL, cn);
cn.Open();
SqlDataReader dr = cm.ExecuteReader();
DataGrid1.DataSource = dr;
//SqlDataSource1.ConnectionString = "server=(local);uid=sa;pwd=sa;database=RealEstate";
//SqlDataSource1.SelectCommand = "select * from RealEstate where EstateID='" + TextBox1.Text + "'";
DataGrid1.DataBind();
cn.Close();
}

分页
protected void DataGrid_Page(Object sender, DataGridPageChangedEventArgs

sqldatareader与allowcustomerpage 冲突,修改查询函数,将sqldatareader向dataset()转换。

你的意思是你一点查询 他又跳到第一页数据页去了是吗?这个很好解决!可以保存当前的页码!然后点了按纽后再跳回那个地址就行了~

在查询的按钮事件里加
DataGrid1.CurrentPageIndex = 0;

SqlDataReader 没有关闭