SqlPager控件使用心得[续]

应一些朋友的邀请,我在这里写我的一些使用和修改SqlPager的详细说明:
1.要使用SqlPager首先要导入您已经修改好的SqlPager.DLL
2.在页面的前台:
<%@ Register TagPrefix="cc1" Namespace="HLSqlPager" Assembly="sqlpager" %>
<cc1:sqlpager id="SqlPager1" runat="server" ConnectionString="server=(local);database=test;uid=sa;pwd=123"
                                        ItemsPerPage
="12" ControlToPaginate="dg" Width="250px" SortMode="DESC"></cc1:sqlpager>
<asp:datagrid id="dg" runat="server" Width="100%" BorderWidth="0" ShowHeader="False" AutoGenerateColumns="False">
                                        
<ItemStyle BorderWidth="0"></ItemStyle>
                                        
<Columns>
                                                                                    
</Columns>
                                    
</asp:datagrid>
<cc1:sqlpager id="SqlPager2" runat="server" ConnectionString="server=(local);database=test;uid=sa;pwd=123"
                                        ItemsPerPage
="12" ControlToPaginate="dg" Width="250px"></cc1:sqlpager>
注意:ControlToPaginate="dg"  这里的dg是你要绑定数据的控件名(只能是DataGrid 或者DataList)

3.后台数据绑定函数
/// <summary>
        
/// SqlPager数据绑定到指定控件
        
/// </summary>
        
/// <param name="SQL">指定查询SQL</param>
        
/// <param name="sortfield">排序字段</param>
        
/// <param name="sortmode">排序方法</param>

        private void BindGrid(string SQL,string sortfield,string sortmode)
        
{                    
            SqlPager1.SelectCommand
=SQL;
            SqlPager2.SelectCommand
=SQL;
            SqlPager1.SortField
=sortfield;
            SqlPager2.SortField
=sortfield;
            
if(sortmode=="DESC")
            
{
                SqlPager1.SortMode
=HLSqlPager.SortMode.DESC;
                SqlPager2.SortMode
=HLSqlPager.SortMode.DESC;
            }

            
else
            
{
                SqlPager1.SortMode
=HLSqlPager.SortMode.ASC;
                SqlPager2.SortMode
=HLSqlPager.SortMode.ASC;
            }
            
            HLSqlPager.SqlPager sqlp
=new HLSqlPager.SqlPager();
            
            
this.DataBind();
        }

4.两个SqlPager联动
private void sql1_pager(object sender, HLSqlPager.PageChangedEventArgs e)
        
{
            SqlPager2.CurrentPageIndex
=SqlPager1.CurrentPageIndex;
            SqlPager2.DataBind();
        }


        
private void sql2_pager(object sender, HLSqlPager.PageChangedEventArgs e)
        
{
            SqlPager1.CurrentPageIndex
=SqlPager2.CurrentPageIndex;
            SqlPager1.DataBind();
        }
private void InitializeComponent()
        
{                         this.SqlPager1.PageIndexChanged += new HLSqlPager.SqlPager.PageChangedEventHandler(this.sql1_pager);
            
this.SqlPager2.PageIndexChanged += new HLSqlPager.SqlPager.PageChangedEventHandler(this.sql2_pager);
            
this.Load += new System.EventHandler(this.Page_Load);

        }

5.切图
{FEE9544D-30BD-4C28-9F1A-3018C7383775}.BMP
6.说明
您可以按照自己的需要对SqlPager进行修改
原版下载地址:下载本文的源代码(英文)
posted @ 2006-09-23 11:47  Hermes.Liu  阅读(1780)  评论(10编辑  收藏  举报