zoukankan      html  css  js  c++  java
  • DataList使用AspNetPager分页

    protected void Page_Load(object sender, EventArgs e)
        
    {
            
    if!IsPostBack )
            
    {
                
    string strSql;
                
    if( Request.QueryString.Count == 0 )
                
    {
                    strSql 
    = "select * from Product where Show=0 order by PID desc";
                    GetAspNetPagerRecordCount( strSql );
                }

                
    else if( Request.QueryString[ "PName" ] == null & Request.QueryString[ "KindID" ] != "全部" )
                
    {
                    strSql 
    = "select * from Product where KindID = " + Request.QueryString[ "KindID" ] + " and Show=0 order by PID desc";
                    GetAspNetPagerRecordCount( strSql );
                }

                
    else if( Request.QueryString[ "PName" ] != null & Request.QueryString[ "KindID" ] != "全部" )
                
    {
                    strSql 
    = "select * from Product where PName like '%" + Request.QueryString[ "PName" ].ToString() + "%' and KindID = " + Request.QueryString[ "KindID" ] + " and Show=0 order by PID desc";
                    GetAspNetPagerRecordCount( strSql );
                }

                
    else if( Request.QueryString[ "PName" ] != null & Request.QueryString[ "KindID" ] == "全部" )
                
    {
                    strSql 
    = "select * from Product where PName like '%" + Request.QueryString[ "PName" ].ToString() + "%' and Show=0 order by PID desc";
                    GetAspNetPagerRecordCount( strSql );
                }

                
    else
                
    {
                    strSql 
    = "select * from Product where Show=0 order by PID desc";
                    GetAspNetPagerRecordCount( strSql );
                }


                
    if( Session[ "UserName" ] == null || Session[ "UserPwd" ] == null )
                
    {
                    BindDataList();
                    
    foreach( DataListItem dl in DataListProduct.Items )
                    
    {
                        System.Web.UI.WebControls.Panel pan 
    = (Panel)dl.FindControl( "Panel1" );
                        pan.Visible 
    = true;

                        System.Web.UI.WebControls.Panel pan1 
    = (Panel)dl.FindControl( "Panel2" );
                        pan1.Visible 
    = false;
                    }

                }

                
    else
                
    {
                    BindDataList();
                    
    foreach( DataListItem dl in DataListProduct.Items )
                    
    {
                        System.Web.UI.WebControls.Panel pan 
    = (Panel)dl.FindControl( "Panel1" );
                        pan.Visible 
    = false;

                        System.Web.UI.WebControls.Panel pan1 
    = (Panel)dl.FindControl( "Panel2" );
                        pan1.Visible 
    = true;
                    }

                }
                
            }

        }


        
    private void GetAspNetPagerRecordCount( string strSql )
        
    {
            DataView dv 
    = DB.GetDataView( strSql );
            
    this.AspNetPager1.RecordCount = dv.Table.Rows.Count;
            
    this.AspNetPager1.PageSize = 12;
        }


        
    protected void BindDataList()
        
    {
            
    string strSql;
            
    if( Request.QueryString.Count == 0 )
            
    {
                strSql 
    = "select * from Product where Show=0 order by PID desc";
                lblMsg.Text 
    = "所有商品";
            }

            
    else if( Request.QueryString["PName"== null & Request.QueryString["KindID"]!="全部" )
            
    {
                strSql 
    = "select * from Product where KindID = " + Request.QueryString[ "KindID" ] + " and Show=0 order by PID desc";
                
    string sql = "select KindName from Kinds where KindID =" + Request.QueryString[ "KindID" ];
                
    string Msg = Convert.ToString( DB.ExecuteScalar( sql ) );
                
    this.lblMsg.Text = Msg;
            }

            
    else if( Request.QueryString["PName"!= null & Request.QueryString["KindID"]!="全部" )
            
    {
                strSql 
    = "select * from Product where PName like '%" + Request.QueryString[ "PName" ].ToString() + "%' and KindID = " + Request.QueryString[ "KindID" ] + " and Show=0 order by PID desc";
                
    this.lblMsg.Text = "搜索结果";
            }

            
    else if( Request.QueryString[ "PName" ] != null & Request.QueryString[ "KindID" ] == "全部" )
            
    {
                strSql 
    = "select * from Product where PName like '%" + Request.QueryString[ "PName" ].ToString() + "%' and Show=0 order by PID desc";
                
    this.lblMsg.Text = "搜索结果";
            }
           
            
    else
            
    {
                strSql 
    = "select * from Product where Show=0 order by PID desc";
                lblMsg.Text 
    = "所有商品";
            }
           

            DataListProduct.DataSource 
    = DB.GetDataSetByAspNetPager( strSql, AspNetPager1 );
            DataListProduct.DataBind(); 
        }

     
    protected void AspNetPager1_PageChanging( object src, Wuqi.Webdiyer.PageChangingEventArgs e )
        
    {
            
    this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            
    if( Session[ "UserName" ] == null || Session[ "UserPwd" ] == null )
            
    {
                BindDataList();
                
    foreach( DataListItem dl in DataListProduct.Items )
                
    {
                    System.Web.UI.WebControls.Panel pan 
    = (Panel)dl.FindControl( "Panel1" );
                    pan.Visible 
    = true;

                    System.Web.UI.WebControls.Panel pan1 
    = (Panel)dl.FindControl( "Panel2" );
                    pan1.Visible 
    = false;
                }

            }

            
    else
            
    {
                BindDataList();
                
    foreach( DataListItem dl in DataListProduct.Items )
                
    {
                    System.Web.UI.WebControls.Panel pan 
    = (Panel)dl.FindControl( "Panel1" );
                    pan.Visible 
    = false;

                    System.Web.UI.WebControls.Panel pan1 
    = (Panel)dl.FindControl( "Panel2" );
                    pan1.Visible 
    = true;
                }

            }

        }

    DB类
    using Wuqi.Webdiyer;

    public static DataSet GetDataSetByAspNetPager( string strSql, AspNetPager AspNetPager )
        
    {
            
    try
            
    {
                OleDbConnection con 
    = CreateCon();
                OleDbDataAdapter sda 
    = new OleDbDataAdapter( strSql, con );
                DataSet ds 
    = new DataSet();
                sda.Fill( ds, AspNetPager.PageSize 
    * ( AspNetPager.CurrentPageIndex - 1 ), AspNetPager.PageSize, "table" );
                con.Close();
                con.Dispose();
                
    return ds;
            }

            
    catch( Exception )
            
    {
                
    throw;
            }

        }
  • 相关阅读:
    滤波器组概念
    镜像滤波器
    fdatool 设计IIR滤波器
    虚拟立体环绕声
    浊音经验阈值和条件
    使用import简化spring的配置 spring import 标签的解析 使用import或加载spring配置时,报错误There is no ID/IDREF 多个Spring配置文件import resource路径配置
    投资大师索罗斯的人生轨迹 索氏投资理论 打跨英格兰银行的人 “魔鬼”索罗斯
    互联网究竟带来中心化还是去中心化 那些赚钱的模式 探讨下互联网会把社会改造成什么样子,到底是中心化还是去中心化
    cmd.exe_参数_启动参数 cmd加启动运行参数 命令
    O'Reilly总裁提姆-奥莱理:什么是Web 2.0
  • 原文地址:https://www.cnblogs.com/Magicam/p/1233156.html
Copyright © 2011-2022 走看看