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

搜索中分页datagrid显示问题!
Button1   的按钮事件Button1_Click,给sqlString字符串赋值,完成对数据库中某表的所有信息查询,同时调用user_DGrid4(sqlString),将查询到的数据绑定到一个datagrid1控件中显示。
页面上定义了几个翻页连接按钮   ,通过调用LBtnNavigation_Click()翻页,在这个里面翻页的时候也要调用user_DGrid4(sqlString);     但此时的sqlString却为初始值空。。怎么解决呢?
后面的搜索功能也要调用user_DGrid4(sqlString);。。。。
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.Configuration;
using   System.Runtime.Serialization;
namespace   WebApplication3.Admin
{
public   class   cjzx_Manage   :   System.Web.UI.Page
{
protected   System.Web.UI.WebControls.Button   Button1;
protected   System.Web.UI.WebControls.Panel   Panel1;
protected   System.Web.UI.WebControls.LinkButton   LBtnFirst;
protected   System.Web.UI.WebControls.LinkButton   LBtnPrev;
protected   System.Web.UI.WebControls.LinkButton   LBtnNext;
protected   System.Web.UI.WebControls.LinkButton   LBtnLast;
protected   System.Web.UI.WebControls.Literal   LtlPageIndex;
protected   System.Web.UI.WebControls.Literal   LtlPageCount;
protected   System.Web.UI.WebControls.Literal   LtlPageSize;
protected   System.Web.UI.WebControls.Literal   LtlRecordCount;
protected   System.Web.UI.WebControls.DataGrid   DataGrid1;
protected   System.Web.UI.WebControls.Button   Del_Button;
protected   System.Web.UI.WebControls.Button   Button2;
protected   System.Web.UI.WebControls.Button   SearchBton;
protected   System.Web.UI.WebControls.DropDownList   SearchStyle;
protected   System.Web.UI.WebControls.TextBox   SText;
protected   System.Web.UI.WebControls.Button   infor_Pass;
private   int   recordCount;
private   int   pageCount;
private   string   sqlString= " ";
private   void   Page_Load(object   sender,   System.EventArgs   e)
{//   在此处放置用户代码以初始化页面

Del_Button.Attributes.Add( "onclick ", "return   confirm( '确定要删除选定的用户信息吗? '); ");
infor_Pass.Attributes.Add( "onclick ", "return   confirm( '确定这些用户信息通过验证吗? '); ");
Button2.Attributes.Add( "onclick ", "return   confirm( '添加提示 '); ");
if(!Page.IsPostBack)
Panel1.Visible=false;
}
//绑定数据
private   void   user_DGrid4(string   sqlString)
{
string   strconn   =   System.Configuration.ConfigurationSettings. AppSettings[ "DSN "];//从Web.config中读取
SqlConnection   conn   =   new   SqlConnection(strconn);
SqlCommand   comm   =   new   SqlCommand(   sqlString   ,conn);
SqlDataAdapter   dataAdapter   =   new   SqlDataAdapter(comm);
DataSet   ds   =   new   DataSet();
dataAdapter.Fill(ds);
recordCount   =   ds.Tables[0].Rows.Count;
//获取当前的页数
pageCount   =   (int)Math.Ceiling(   recordCount   *   1.0   /   PageSize);
if(recordCount   ==0)
{this.DataGrid1.CurrentPageIndex   =   0;}
else   if(this.DataGrid1.CurrentPageIndex   > =   pageCount)
{this.DataGrid1.CurrentPageIndex   =   pageCount   -   1;}