日期:2014-05-20  浏览次数:20494 次

用SqlDataSource筛选后GRIDVIEW的自动分页功能怎么让他使用筛选后的结果分页
用SqlDataSource筛选后GRIDVIEW的自动分页功能怎么让他使用筛选后的结果分页

------解决方案--------------------
这个简单!
使用ViewState

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;
using System.Collections.Specialized;
using System.Drawing.Imaging;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ViewState[ "sql "] = "select * from lines ";
}
this.GridBind();
}
private void GridBind()
{
string errInfo = String.Empty;
DataSet ds = new DataSet();
if (!conn.OperateDB(ViewState[ "sql "].ToString(), ref ds, ref errInfo))
{
Response.Write(errInfo);
return;
}
else
{
DataView dv = new DataView(ds.Tables[0]);
this.GridView1.DataSource= dv;
if (this.GridView1.PageIndex > this.GridView1.PageCount - 1)
GridView1.PageIndex = 0;
GridView1.DataBind();
}
}
private void Button3_Click(object sender, System.EventArgs e)
{
GridView1.PageIndex = 0;

ViewState[ "sql "]= "查询语句 ";
this.GridBind();
}
}