原创--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,一经查实,立即删除!

相关文章

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

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

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

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

拼音输入法功能大比拼

使用电脑工作或在互联网大潮中冲浪的朋友都离不开输入法的使用&#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。但是…

代码优化导致的奇葩问题

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

深度:关于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;到底使用哪个平台开发的企业级应用性能…

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

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

[教程]win10 ,ubuntu双系统安装避坑指南

这篇博客可以解决1.如何安装win10,ubuntu双系统2.如何使用win10引导Ubuntu&#xff0c;并且设置win10引导界面点击阅读原文获取更多信息。win10,ubuntu双系统的安装为什么要装双系统&#xff0c;之前用的虚拟机&#xff0c;但是虚拟机没有显卡&#xff0c;使用gazebo之类的3D仿…

Type-C PD充电简介

一、Type-C简介自1998年以来&#xff0c;USB发布至今&#xff0c;USB已经走过20个年头有余了。在这20年间&#xff0c;USB-IF组织发布N种接口状态&#xff0c;包括A口、B口、MINI-A、MINI-B、Micro-A、Micro-B等等接口形态&#xff0c;由于各家产品不同&#xff0c;不同产品使用…

Linux字符设备驱动内幕

哈喽&#xff0c;我是老吴&#xff0c;继续记录我的学习心得。一、保持专注的几个技巧将最重要的事放在早上做。待在无干扰环境下&#xff0c;比如图书馆。意识到刚坐下开始投入工作前&#xff0c;有点负面小情绪是特别正常的现象。让“开心一刻”成为计划的一部分。拥有合情合…

旧地重游

光阴飞逝1991年跟随父母搬迁至长沙&#xff0c;至今已有16年。2007年春节舅妈大寿借此机会回到儿时旧地以了多年来的心愿。经过1个小时左右颠簸终于快回到儿时生长的地方&#xff0c;那里的路面年久失修&#xff0c;经过昨天的大雨&#xff0c;已经坑坑洼洼路面到处积水&#x…

我要不要离职?

1#读者提问来到四线城市的小公司&#xff0c;其他员工都是公司主动找到他们转正的&#xff0c;有的一个月有的三个月&#xff0c;而我半年过去了&#xff0c;以为时间到了也跟他们一样自动帮我转正。然而没有&#xff0c;昨天忍不住问了公司&#xff0c;今天就拿转正表来给我填…

搞懂进程组、会话、控制终端关系,才能明白守护进程干嘛的?

守护进程概念&#xff1a;守护进程&#xff0c;也就是通常所说的Daemon进程&#xff0c;是Linux中的后台服务进程。周期性的执行某种任务或等待处理某些发生的事件。Linux系统有很多守护进程&#xff0c;大多数服务都是用守护进程实现的。比如&#xff1a;像我们的tftp&#xf…

关于编译C#文件

使用csc.exe编译非控制台应用程序,常使用/target选项此选项可简写为/t,用来指定要创建的文件类型. 如编译一个类库文件(dll)Class1.cs: namespaceTest...{ /**//// <summary> /// Class1 的摘要说明。 /// </summary> public class Class1 ...{ …

【速来抢】iPhone12、STM32开发板、1024元现金红包…打包免费送!!!

没错&#xff01;华清远见在做1024狂欢节活动今年他们“玩”的有点大参与活动&#xff0c;抽取幸运锦鲤下面21件惊喜大礼&#xff0c;打包全部带回家????参与方式&#xff1a;扫码下方二维码&#xff0c;进活动群获取抽奖链接&#xff0c;参与抽奖????福利2除了万元锦鲤…

1024,第 15 届「中国内核开发者大会」 参会指南(议程全剧透)

各位好&#xff0c;第 15 届「中国内核开发者大会」即将开幕&#xff0c;这些参会指南请提前收藏好&#xff1a;2020「中国内核开发者大会」&#xff08;以下简称 CLK&#xff09;将在 2020 年 10 月 24 日举办&#xff0c;线上线下同步进行&#xff0c;线上由 CSDN 进行全网直…

1024对话内核大神谢宝友

我看了CSDN的采访&#xff0c;感觉比较官方&#xff0c;不知道是不是编辑的原因把一些内容给隐藏了&#xff0c;所以我还是想完整的内容放出来给大家看看&#xff0c;这些问题&#xff0c;可能是很多后辈程序员非常关心的。今天是1024节&#xff0c;这个数字对于写在电脑前写代…