gridview搜索后分页的问题,请大家帮帮忙,不要那种判定文本框是否的方法,谢谢大家!

解决方案 »

  1.   

    搜索后分页?当前页数据搜索然后分页---》重新绑定结果就OK了,搜索结果<=当前数据总量获得分页后绑定?
      

  2.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.OleDb;public partial class ok : System.Web.UI.Page
    {   
        protected void Page_Load(object sender, EventArgs e)
        {
            string tempusername;
            Response.Write(Application["username"]);
            if (Session["values"] == null)
            {
                //Label4.Visible = false;
                TextBox1.Enabled = false;
                TextBox2.Enabled = false;
                TextBox3.Enabled = false;
            }
            else
            {
                Label4.Visible = true;
                //TextBox1.Enabled = false;
                //TextBox2.Enabled = false;
                //TextBox3.Enabled = false;
            }
            if (!IsPostBack)
            {            DataBind();
                
            }       }
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;       DataBind();
        }
        private void DataBind()
        {
            string db = Server.MapPath("db1.mdb");
            string ConnectionStr = "Data Source=" + db + ";Provider=Microsoft.Jet.OLEDB.4.0";
            OleDbConnection myConn = new OleDbConnection(ConnectionStr);
            myConn.Open();
            string sqlselect = "select * from message where username='song'";
            OleDbCommand mycommand1 = new OleDbCommand(sqlselect, myConn);
            OleDbDataAdapter myadapter = new OleDbDataAdapter();
            myadapter.SelectCommand = mycommand1;
            DataSet mydata = new DataSet();
            myadapter.Fill(mydata);        GridView1.DataSource = mydata.Tables[0].DefaultView;
            GridView1.DataBind();
        
        }
        //GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)       protected void Button1_Click(object sender, EventArgs e)
        {
            string tempusername = TextBox1.Text;
            string temptitle = TextBox2.Text;
            string tempmessage = TextBox3.Text;
            if (tempusername != "" && temptitle != "" && tempmessage != "")
            {
                string db = Server.MapPath("db1.mdb");
                string ConnectionStr = "Data Source=" + db + ";Provider=Microsoft.Jet.OLEDB.4.0";
                OleDbConnection myConn = new OleDbConnection(ConnectionStr);
                myConn.Open();
                string sql = "insert into message(username,title,message) values('" + tempusername + "','" + temptitle + "','" + tempmessage + "')";            OleDbCommand mycommand = new OleDbCommand(sql, myConn);
                mycommand.ExecuteNonQuery();
                myConn.Close();
                Response.Write("发表留言成功!");
                //Response.Redirect("ok.aspx");
            }
        }
       
       
    }
      

  3.   

    ViewState记录是搜索模式还是全部记录模式,如果是搜索模式,记录搜索的关键词。然后重新绑定数据即刻。也可引用ajax技术,构造异步数据传递,实现客户端的数据绑定分页,但比较麻烦。服务器重新绑定的话,比较耗资源。~~