原创--DataGrid自动分页例子,通过存储过程

通过存储过程来进行DataGrid自动分页,效率很高,可以进行百万和千万级的分页

自己通过50万条记录测试,翻至任何页,需时小于一秒

呵呵,仅供自己以后察看使用,所以代码写的不很规范

所需的存储过程如下:

None.gifCREATE PROCEDURE UP_GetRecordByPage
None.gif    @tblName      varchar(
255),       -- 表名
None.gif    @fldName      varchar(
255),       -- 主键字段名
None.gif    @PageSize     
int = 10,           -- 页尺寸
None.gif    @PageIndex    
int = 1,            -- 页码
None.gif    @IsReCount    bit 
= 1,            -- 返回记录总数, 非 0 值则返回
None.gif    @OrderType    bit 
= 0,            -- 设置排序类型, 非 0 值则降序
None.gif    @strWhere     varchar(
1000= ''  -- 查询条件 (注意: 不要加 where)
None.gifAS
None.gif
None.gifdeclare @strSQL   varchar(
6000)       -- 主语句
None.gifdeclare @strTmp   varchar(
100)        -- 临时变量
None.gifdeclare @strOrder varchar(
400)        -- 排序类型
None.gif
None.gif
if @OrderType != 0
None.gifbegin
None.gif    
set @strTmp = '<(select min'
None.gif    
set @strOrder = ' order by [' + @fldName +'] desc'
None.gifend
None.gif
else
None.gifbegin
None.gif    
set @strTmp = '>(select max'
None.gif    
set @strOrder = ' order by [' + @fldName +'] asc'
None.gifend
None.gif
None.gif
set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
None.gif    
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
None.gif    
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
None.gif    
+ @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'
None.gif    
+ @strOrder
None.gif
None.gif
if @strWhere != ''
None.gif    
set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
None.gif        
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
None.gif        
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
None.gif        
+ @fldName + '] from [' + @tblName + '] where ' + @strWhere + ' '
None.gif        
+ @strOrder + ') as tblTmp) and ' + @strWhere + ' ' + @strOrder
None.gif
None.gif
if @PageIndex = 1
None.gifbegin
None.gif    
set @strTmp =''
None.gif    
if @strWhere != ''
None.gif        
set @strTmp = ' where ' + @strWhere
None.gif
None.gif    
set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
None.gif        
+ @tblName + ']' + @strTmp + ' ' + @strOrder
None.gifend
None.gif
None.gif
if @IsReCount != 0
None.gif    
set @strSQL = 'select count(*) as Total from [' + @tblName + ']'+' where ' + @strWhere
None.gif
None.gifexec (@strSQL)
None.gifGO
None.gif





Windows C# 页面代码

None.gifusing System;
None.gif
using System.Collections;
None.gif
using System.ComponentModel;
None.gif
using System.Data;
None.gif
using System.Drawing;
None.gif
using System.Web;
None.gif
using System.Web.SessionState;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.HtmlControls;
None.gif
using System.Data.SqlClient;
None.gif
None.gif
namespace _0921test
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// DataGridMostDataDisplay 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class DataGridMostDataDisplay : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected System.Web.UI.WebControls.Label Label2;
InBlock.gif        
protected System.Web.UI.WebControls.DataGrid dgShowC;        
InBlock.gif        
protected System.Web.UI.HtmlControls.HtmlForm Form1;
InBlock.gif        
protected System.Web.UI.WebControls.TextBox TextBox1;
InBlock.gif        
protected System.Web.UI.WebControls.Button btnGOTO;
InBlock.gif        
protected System.Web.UI.WebControls.ImageButton ibtnFirstPage;
InBlock.gif        
protected System.Web.UI.WebControls.ImageButton ibtnPrevousPage;
InBlock.gif        
protected System.Web.UI.WebControls.ImageButton ibtnNextPage;
InBlock.gif        
protected System.Web.UI.WebControls.ImageButton ibtnLastPage;
InBlock.gif        
protected System.Web.UI.WebControls.Label Label1;
InBlock.gif        
protected System.Data.SqlClient.SqlConnection sqlConnection1;
InBlock.gif
InBlock.gif        
InBlock.gif        
static int Records = 0;         //记录总数
InBlock.gif
        int PageSize = 10;       //页大小
InBlock.gif
        static int PageIndex = 1;   //当前页
InBlock.gif
        static int PageCount = 0;
InBlock.gif        
protected System.Web.UI.WebControls.Label Label3;
InBlock.gif        
protected System.Web.UI.WebControls.Label Label4;
InBlock.gif        
protected System.Web.UI.WebControls.Label Label5;
InBlock.gif        
string strWhere = "";
InBlock.gif        
protected System.Web.UI.WebControls.Button btnBindData;
InBlock.gif        
protected System.Web.UI.WebControls.TextBox txtShipAddress;
InBlock.gif        
protected System.Web.UI.WebControls.TextBox txtShipName;
InBlock.gif        
static string strWhereO = "";
InBlock.gif    
InBlock.gif
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 在此处放置用户代码以初始化页面
InBlock.gif
            
InBlock.gif            
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
InBlock.gif            
this.btnBindData.Click += new System.EventHandler(this.btnBindData_Click);
InBlock.gif            
this.dgShowC.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgShowC_ItemCreated);
InBlock.gif            
this.dgShowC.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgShowC_PageIndexChanged);
InBlock.gif            
this.dgShowC.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgShowC_ItemDataBound);
InBlock.gif            
this.ibtnFirstPage.Click += new System.Web.UI.ImageClickEventHandler(this.ibtnFirstPage_Click);
InBlock.gif            
this.ibtnPrevousPage.Click += new System.Web.UI.ImageClickEventHandler(this.ibtnPrevousPage_Click);
InBlock.gif            
this.ibtnNextPage.Click += new System.Web.UI.ImageClickEventHandler(this.ibtnNextPage_Click);
InBlock.gif            
this.ibtnLastPage.Click += new System.Web.UI.ImageClickEventHandler(this.ibtnLastPage_Click);
InBlock.gif            
this.btnGOTO.Click += new System.EventHandler(this.btnGOTO_Click);
InBlock.gif            
// 
InBlock.gif            
// sqlConnection1
InBlock.gif            
// 
InBlock.gif
            this.sqlConnection1.ConnectionString = "workstation id=WANGSZ;packet size=4096;integrated security=SSPI;data source=WANGS" +
InBlock.gif                
"Z;persist security info=False;initial catalog=Northwind";
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif
InBlock.gif        
InBlock.gif
InBlock.gif        
private void BindGridC()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
string connectionString = "workstation id=WANGSZ;packet size=4096;integrated security=SSPI;data source=WANGSZ;persist security info=False;initial catalog=Northwind";
InBlock.gif            
InBlock.gif            
InBlock.gif            
string sqlstr = "SELECT * FROM Test where TID < 1000";
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
using (SqlConnection connection = new SqlConnection(connectionString))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    DataSet ds 
= new DataSet();
InBlock.gif                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        connection.Open();                    
InBlock.gif                        SqlDataAdapter Dta
= new SqlDataAdapter(sqlstr,connection);
InBlock.gif                        Dta.Fill(ds,
"ds");
InBlock.gif                        Dta.Dispose();
InBlock.gif                        
this.dgShowC.DataSource = ds;
InBlock.gif                        
this.dgShowC.VirtualItemCount=5;
InBlock.gif                        
this.dgShowC.DataBind();
InBlock.gif                        Records 
= ds.Tables[0].Rows.Count;
InBlock.gif                        
this.Label1.Text = "共有: "+Records.ToString()+" 记录";
InBlock.gif                        
this.Label2.Text = "页数: "+PageIndex+"/"+Records/20;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
catch(System.Data.SqlClient.SqlException ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{                
InBlock.gif                        
throw new Exception(ex.Message);
ExpandedSubBlockEnd.gif                    }
            
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch(SqlException SQLexc)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Response.Write(
"提取数据时出现错误:" + SQLexc.ToString()); 
ExpandedSubBlockEnd.gif            }
 
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
InBlock.gif        
//分页获取数据列表
InBlock.gif
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            SqlParameter[] parameters 
= dot.gif{
InBlock.gif                                            
new SqlParameter("@tblName", SqlDbType.VarChar, 255),
InBlock.gif                                            
new SqlParameter("@fldName", SqlDbType.VarChar, 255),
InBlock.gif                                            
new SqlParameter("@PageSize", SqlDbType.Int),
InBlock.gif                                            
new SqlParameter("@PageIndex", SqlDbType.Int),
InBlock.gif                                            
new SqlParameter("@IsReCount", SqlDbType.Bit),
InBlock.gif                                            
new SqlParameter("@OrderType", SqlDbType.Bit),
InBlock.gif                                            
new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
ExpandedSubBlockEnd.gif            }
;
InBlock.gif            parameters[
0].Value = "Test";
InBlock.gif            parameters[
1].Value = "TID";
InBlock.gif            parameters[
2].Value = PageSize;
InBlock.gif            parameters[
3].Value = PageIndex;
InBlock.gif            parameters[
4].Value = 0;
InBlock.gif            parameters[
5].Value = 0;
InBlock.gif            parameters[
6].Value = strWhere;    
InBlock.gif            
return RunProcedure("UP_GetRecordByPage",parameters,"ds");
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//分页获取数据列表
InBlock.gif
        public DataSet GetListC(int PageSize,int PageIndex,string strWhere)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            SqlParameter[] parameters 
= dot.gif{
InBlock.gif                                            
new SqlParameter("@tblName", SqlDbType.VarChar, 255),
InBlock.gif                                            
new SqlParameter("@fldName", SqlDbType.VarChar, 255),
InBlock.gif                                            
new SqlParameter("@PageSize", SqlDbType.Int),
InBlock.gif                                            
new SqlParameter("@PageIndex", SqlDbType.Int),
InBlock.gif                                            
new SqlParameter("@IsReCount", SqlDbType.Bit),
InBlock.gif                                            
new SqlParameter("@OrderType", SqlDbType.Bit),
InBlock.gif                                            
new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
ExpandedSubBlockEnd.gif            }
;
InBlock.gif            parameters[
0].Value = "Test";
InBlock.gif            parameters[
1].Value = "TID";
InBlock.gif            parameters[
2].Value = PageSize;
InBlock.gif            parameters[
3].Value = PageIndex;
InBlock.gif            parameters[
4].Value = 1;
InBlock.gif            parameters[
5].Value = 0;
InBlock.gif            parameters[
6].Value = strWhere;    
InBlock.gif            
return RunProcedure("UP_GetRecordByPage",parameters,"ds");
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
InBlock.gif
InBlock.gif        
// 创建 SqlCommand 对象实例(用来返回一个整数值)    
InBlock.gif
        private static SqlCommand BuildIntCommand(SqlConnection connection,string storedProcName, IDataParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            SqlCommand command 
= BuildQueryCommand(connection,storedProcName, parameters );
InBlock.gif            command.Parameters.Add( 
new SqlParameter ( "ReturnValue",
InBlock.gif                SqlDbType.Int,
4,ParameterDirection.ReturnValue,
InBlock.gif                
false,0,0,string.Empty,DataRowVersion.Default,null ));
InBlock.gif            
return command;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// 执行存储过程,返回影响的行数        
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="storedProcName">存储过程名</param>
InBlock.gif        
/// <param name="parameters">存储过程参数</param>
InBlock.gif        
/// <param name="rowsAffected">影响的行数</param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public static int RunProcedure(string storedProcName, IDataParameter[] parameters, out int rowsAffected )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string connectionString = "workstation id=WANGSZ;packet size=4096;integrated security=SSPI;data source=WANGSZ;persist security info=False;initial catalog=Northwind";
InBlock.gif            
using (SqlConnection connection = new SqlConnection(connectionString))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
int result;
InBlock.gif                connection.Open();
InBlock.gif                SqlCommand command 
= BuildIntCommand(connection,storedProcName, parameters );
InBlock.gif                rowsAffected 
= command.ExecuteNonQuery();
InBlock.gif                result 
= (int)command.Parameters["ReturnValue"].Value;
InBlock.gif                
//Connection.Close();
InBlock.gif
                return result;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
// 执行存储过程
InBlock.gif
        public static DataSet RunProcedure(string storedProcName, IDataParameter[] parameters, string tableName )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string connectionString = "workstation id=WANGSZ;packet size=4096;integrated security=SSPI;data source=WANGSZ;persist security info=False;initial catalog=Northwind";
InBlock.gif            
using (SqlConnection connection = new SqlConnection(connectionString))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                DataSet dataSet 
= new DataSet();
InBlock.gif                connection.Open();
InBlock.gif                SqlDataAdapter sqlDA 
= new SqlDataAdapter();
InBlock.gif                sqlDA.SelectCommand 
= BuildQueryCommand(connection, storedProcName, parameters );
InBlock.gif                sqlDA.Fill( dataSet, tableName );
InBlock.gif                connection.Close();
InBlock.gif                
return dataSet;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
InBlock.gif        
InBlock.gif        
// 构建 SqlCommand 对象(用来返回一个结果集,而不是一个整数值)
InBlock.gif
        private static SqlCommand BuildQueryCommand(SqlConnection connection,string storedProcName, IDataParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{            
InBlock.gif            SqlCommand command 
= new SqlCommand( storedProcName, connection );
InBlock.gif            command.CommandType 
= CommandType.StoredProcedure;
InBlock.gif            
foreach (SqlParameter parameter in parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                command.Parameters.Add( parameter );
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return command;            
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif        
//可以得到@@RowCount
InBlock.gif
        public static object GetSingle(string SQLString)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string connectionString = "workstation id=WANGSZ;packet size=4096;integrated security=SSPI;data source=WANGSZ;persist security info=False;initial catalog=Northwind";
InBlock.gif            
using (SqlConnection connection = new SqlConnection(connectionString))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
using(SqlCommand cmd = new SqlCommand(SQLString,connection))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        connection.Open();
InBlock.gif                        
object obj = cmd.ExecuteScalar();
InBlock.gif                        
if((Object.Equals(obj,null))||(Object.Equals(obj,System.DBNull.Value)))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{                    
InBlock.gif                            
return null;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            
return obj;
ExpandedSubBlockEnd.gif                        }
                
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
catch(System.Data.SqlClient.SqlException e)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{                        
InBlock.gif                        connection.Close();
InBlock.gif                        
throw new Exception(e.Message);
ExpandedSubBlockEnd.gif                    }
    
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif        
//根据存储过程绑定
InBlock.gif
        private void BindGridStore()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            strWhere 
= " ShipName like "+"'%"+ this.txtShipName.Text +"%' and ShipAddress like "+"'%"+ this.txtShipAddress.Text +"%'";
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{                    
InBlock.gif                    DataSet ds 
= GetList(PageSize,PageIndex,strWhere);
InBlock.gif
InBlock.gif                    
this.dgShowC.DataSource=ds.Tables[0].DefaultView;
InBlock.gif                    
this.dgShowC.DataBind();
InBlock.gif                    
InBlock.gif                    
if(strWhere != strWhereO)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        DataSet dsrc 
= GetListC(PageSize,PageIndex,strWhere);
InBlock.gif                        
if(dsrc.Tables[0].Columns.Count==1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            Records 
= Convert.ToInt32(dsrc.Tables[0].Rows[0][0].ToString());                            ;
InBlock.gif                            
this.Label1.Text = "总记录数:" + Records.ToString();
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        strWhereO 
= strWhere;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    PageCount 
= Records/10;
InBlock.gif                    
this.Label2.Text = "当前页数:"+PageIndex+"/"+PageCount;
InBlock.gif                    
ExpandedSubBlockEnd.gif                }

InBlock.gif                
catch(System.Data.SqlClient.SqlException ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{                
InBlock.gif                    
throw new Exception(ex.Message);
ExpandedSubBlockEnd.gif                }
                    
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch(SqlException SQLexc)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Response.Write(
"提取数据时出现错误:" + SQLexc.ToString()); 
ExpandedSubBlockEnd.gif            }
 
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private void dgShowC_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.dgShowC.CurrentPageIndex = e.NewPageIndex;
InBlock.gif            PageIndex 
= e.NewPageIndex+1;
InBlock.gif            
this.BindGridC();
InBlock.gif            
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//控制四个翻页按钮的显示 
InBlock.gif
        private void ibtnVisible(bool first,bool previous,bool next,bool last)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.ibtnFirstPage.Visible=first;
InBlock.gif            
this.ibtnPrevousPage.Visible=previous;
InBlock.gif            
this.ibtnNextPage.Visible=next;
InBlock.gif            
this.ibtnLastPage.Visible=last;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private void btnBindData_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//this.BindGridC();
InBlock.gif
            this.BindGridStore();
InBlock.gif            PageIndex 
= 1;
InBlock.gif            
this.ibtnVisible(false,false,true,true);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void dgShowC_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//鼠标移动到每项时颜色交替效果
InBlock.gif
            if (e.Item.ItemType!=ListItemType.Header)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{    
InBlock.gif                e.Item.Attributes.Add(
"OnMouseOut""this.style.backgroundColor='Transparent';this.style.color='Black'");
InBlock.gif                e.Item.Attributes.Add(
"OnMouseOver""this.style.backgroundColor='#cacee1';this.style.color='Blue'");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
InBlock.gif            
//鼠标的形状为小手
InBlock.gif
            e.Item.Attributes["style"= "Cursor:hand";
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
InBlock.gif
InBlock.gif        
private void ibtnFirstPage_Click(object sender, System.Web.UI.ImageClickEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.ibtnVisible(false,false,true,true);
InBlock.gif            PageIndex 
= 1;
InBlock.gif            
this.BindGridStore();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void ibtnPrevousPage_Click(object sender, System.Web.UI.ImageClickEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{            
InBlock.gif            
if(PageIndex == 2)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.ibtnVisible(false,false,true,true);
InBlock.gif                PageIndex 
= 1;
InBlock.gif                
this.BindGridStore();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.ibtnVisible(true,true,true,true);
InBlock.gif                PageIndex 
= PageIndex -1;
InBlock.gif                
this.BindGridStore();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void ibtnNextPage_Click(object sender, System.Web.UI.ImageClickEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{            
InBlock.gif            
if(PageIndex == Records/10-1)
InBlock.gif                
this.ibtnVisible(true,true,false,false);
InBlock.gif            
else
InBlock.gif                
this.ibtnVisible(true,true,true,true);
InBlock.gif            PageIndex 
= PageIndex + 1;
InBlock.gif            
this.BindGridStore();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void ibtnLastPage_Click(object sender, System.Web.UI.ImageClickEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.ibtnVisible(true,true,false,false);
InBlock.gif            PageIndex 
= PageCount;
InBlock.gif            
this.BindGridStore();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void dgShowC_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(e.Item.ItemType == ListItemType.Pager)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{    
InBlock.gif                
foreach (Control c in e.Item.Cells[0].Controls)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (c is Label)  //当前页数
ExpandedSubBlockStart.gifContractedSubBlock.gif
                    dot.gif{
InBlock.gif                        Label lblpage
=(Label)c;
InBlock.gif                        
//      lblpage.ForeColor= System.Drawing.ColorTranslator.FromHtml("#e78a29"); //#e78a29 ,#FF0000     
InBlock.gif                        
//      lblpage.Font.Bold=true;
InBlock.gif
                        lblpage.Text="[<font color=#e78a29><b>"+lblpage.Text+"</b></font>]";     
InBlock.gif                        
//((Label)c).ForeColor = System.Drawing.Color.Green;      
InBlock.gif                        
//      break;
ExpandedSubBlockEnd.gif
                    }

InBlock.gif                    
if(c is LinkButton) //链接的其他页数
ExpandedSubBlockStart.gifContractedSubBlock.gif
                    dot.gif{      
InBlock.gif                        LinkButton linkButton 
= (LinkButton)c;       
InBlock.gif                        linkButton.Text 
= "[" + linkButton.Text+"]"
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }
    
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif        
//跳转页面
InBlock.gif
        private void btnGOTO_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            PageIndex 
= System.Convert.ToInt32(this.TextBox1.Text);
InBlock.gif            
this.BindGridStore();
InBlock.gif            
this.TextBox1.Text = "";
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void btnBindData_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif        
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/467159.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

常用正则表达式整理

一、校验数字的表达式 1 数字&#xff1a;^[0-9]*$ 2 n位的数字&#xff1a;^\d{n}$ 3 至少n位的数字&#xff1a;^\d{n,}$ 4 m-n位的数字&#xff1a;^\d{m,n}$ 5 零和非零开头的数字&#xff1a;^(0|[1-9][0-9]*)$ 6 非零开头的最多带两位小数的数字&#xff1a;^([1-9][…

我看完大连理工研究生的遗书之后

可能是因为年纪大的一丢丢&#xff0c;看到这类新闻会觉得难受&#xff0c;也可能是因为自己也是父亲了&#xff0c;想到这位同学父亲的情况更加受不了。然后回头想想自己这些年的经历&#xff0c;很多次也有过结束生命来解决问题的想法&#xff0c;每次到了最关键的时候&#…

nyoj91 阶乘之和

阶乘之和 时间限制&#xff1a;3000 ms | 内存限制&#xff1a;65535 KB难度&#xff1a;3描述给你一个非负数整数n&#xff0c;判断n是不是一些数&#xff08;这些数不允许重复使用&#xff0c;且为正数&#xff09;的阶乘之和&#xff0c;如91&#xff01;2!3!&#xff0c;…

面试官:如何写出让 CPU 跑得更快的代码?

前言代码都是由 CPU 跑起来的&#xff0c;我们代码写的好与坏就决定了 CPU 的执行效率&#xff0c;特别是在编写计算密集型的程序&#xff0c;更要注重 CPU 的执行效率&#xff0c;否则将会大大影响系统性能。CPU 内部嵌入了 CPU Cache&#xff08;高速缓存&#xff09;&#x…

bzoj 1058: [ZJOI2007]报表统计

Description 小Q的妈妈是一个出纳&#xff0c;经常需要做一些统计报表的工作。今天是妈妈的生日&#xff0c;小Q希望可以帮妈妈分担一些工 作&#xff0c;作为她的生日礼物之一。经过仔细观察&#xff0c;小Q发现统计一张报表实际上是维护一个可能为负数的整数数列&#xff0c;…

拼音输入法功能大比拼

使用电脑工作或在互联网大潮中冲浪的朋友都离不开输入法的使用&#xff0c;输入法种类繁多&#xff0c;让新接触电脑的朋友目不暇接&#xff0c;难以确定哪一款才是最适合的自己的输入法。 一、拼音走向主流 五笔逐渐衰落尽管目前市场上的输入法种类繁多&#xff0c;各种各样的…

循序渐进PYTHON3(十三) --8-- DJANGO之ADMIN

admin简单使用&#xff1a; 1.urls.py2.settings.py3.models.pyfrom django.db import modelsclassUserInfo(models.Model): uid models.AutoField(primary_keyTrue) user_name models.CharField(max_length30) email models.EmailField() memo models.TextField() img mo…

你见过出道即巅峰吗?

我不知道你们见过没有&#xff0c;反正我见过了。这个消息是我周五上班的时候收到的&#xff0c;这个是一位非电子专业转行嵌入式的同学&#xff0c;之前加我微信后&#xff0c;聊的不是很多&#xff0c;但是非常惊讶的是&#xff0c;刚刚毕业就拿到了一份非常不错的offer。但是…

Turing equation

问题 F: F.Turing equation 时间限制: 1 Sec 内存限制: 128 MB 提交: 19 解决: 1 [提交][状态][讨论版] 题目描述 The fight goes on,whether to store numbers starting with their most significant digit ortheir least significant digit. Sometimes this is alsocall…

vmware linux

从今天才开始linux的系统学习。在虚拟机里的linux-as-3不能上网&#xff0c; 记得好久以前就有这种问题。一直以为是在配置vmware时选的桥接方式有误。但是改后&#xff0c;也不能上网。怀疑根本就不能和路由器连通。首先确定物理连接&#xff0c;当在命令行下设好ip与netmask…

代码优化导致的奇葩问题

这个是今天在微信群里讨论的一个问题&#xff0c;先看图片点击查看大图代码流程大概是这个样子的点击查看大图查看 length 和 space1 的值&#xff0c;明显看到 length 小于 space1 的值&#xff0c;即使是这样小白都能搞懂流程的情况下&#xff0c;代码还是跑到else里面区执行…

实践:创建异步 HTTP 处理器

异步 HTTP 处理器允许你启动外部进程&#xff08;比如一个调用远程服务器的方法&#xff09;&#xff0c;并且在无需等待外部进程被完成的情况之下继续处理器自身的处理。另外&#xff0c;在处理一个异步 HTTP 处理器的期间&#xff0c;ASP.NET 还会把通常用于外部进程的线程返…

nyoj187 快速查找素数

快速查找素数 时间限制&#xff1a;1000 ms | 内存限制&#xff1a;65535 KB难度&#xff1a;3描述现在给你一个正整数N&#xff0c;要你快速的找出在2.....N这些数里面所有的素数。 输入给出一个正整数数N(N<2000000)但N为0时结束程序。测试数据不超过100组输出将2~N范围…

深度:关于Linux内核最硬核的文章

来源 &#xff1a;头条号Linux学习教程&#xff0c;冰凌块儿01前言本文主要讲解什么是Linux内核&#xff0c;以及通过多张图片展示Linux内核的作用与功能&#xff0c;以便于读者能快速理解什么是Linux内核&#xff0c;能看懂Linux内核。拥有超过1300万行的代码&#xff0c;Linu…

springaop----springaop的使用(一)

与大多数技术一样&#xff0c; AOP 已经形成了自己的术语。描述切面的常用术语有通知&#xff08;advice&#xff09;、切点&#xff08;pointcut&#xff09;和连接点&#xff08;join point&#xff09;。从今天开始&#xff0c;我们对spring的切面编程做一个总结。她们都是你…

Microsoft .NET Pet Shop 4 架构与技术分析

1&#xff0e;项目概述与架构分析微软刚推出了基于ASP.NET 2.0下的Pet Shop 4, 该版本有了一个全新的用户界面。是研究ASP.NET 2.0的好范例啊&#xff0c;大家都知道&#xff0c;一直以来&#xff0c;在.NET和Java之间争论不休&#xff0c;到底使用哪个平台开发的企业级应用性能…

nyoj 14 会场安排问题

会场安排问题 时间限制&#xff1a;3000 ms | 内存限制&#xff1a;65535 KB难度&#xff1a;4描述学校的小礼堂每天都会有许多活动&#xff0c;有时间这些活动的计划时间会发生冲突&#xff0c;需要选择出一些活动进行举办。小刘的工作就是安排学校小礼堂的活动&#xff0c;…

想领取开发套件,就来参加AIoT开发者大赛

你心目中的智慧校园长什么样&#xff1f; 传统校园上自习得排队等位&#xff0c;智慧校园手机一键查询空位&#xff0c;抢座占位有序便利&#xff1b; 传统校园灯光全靠手动调整&#xff0c;智慧校园灯光无感调控&#xff0c;营造全新智能光照环境&#xff1b;传统校园安全防护…

Notadd 2.0 全新 Node.js 版本~ (开发中) [从 PHP 到 node 的踩坑记]

对于 Notadd 我们本来期望它实现更多... 尽管我们也尝试做了很多努力&#xff0c;但是由于 PHP 本身的局限&#xff0c;以及考虑到开发环境配置的复杂程度&#xff0c;最终使用了折中方案。接下来&#xff0c;我们谈谈整个技术选型历程&#xff0c;也供今后相关开发者做借鉴和参…

SQL Server 数据库构架

Microsoft SQL Server™ 2000 数据存储在数据库中。在数据库中&#xff0c;数据被组织到用户可以看见的逻辑组件中。数据库还可以按物理方式&#xff0c;在磁盘上作为两个或更多的文件实现。使用数据库时使用的主要是逻辑组件&#xff0c;例如表、视图、过程和用户。文件的物理…