惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

博客园 - 鱿鱼

关于在VS2005环境下无法从源视图切换到设计视图的解决方案(转) - 鱿鱼 - 博客园 DotNet2005快捷键 什么是托管 LINQ,语言级集成查询(Language INtegrated Query) ORM(Object Relational Mapping) Step by Step 创建一个简单的Silverlight应用程序(转自微软学生中心) SiliverLight的安装配置 预览大尺寸图片的解决方案 uploadfile和Image实现图片预览 - 鱿鱼 - 博客园 解决datalist中radiobutton单选的问题 .NET委托:一个C#睡前故事 关于ModalPopup控件不能调用CS事件代码的问题 对.NET中三层结构的解释 日期格式的正则表达式 关于判断sql查询记录集为空的问题 无刷新聊天室(asp.net1.1) 无刷新聊天室简易版(asp.net2.0) asp.net2.0更改login控件对密码安全性的要求(转) 一个上传文件的免费空间(转)
datalist分页 - 鱿鱼 - 博客园
鱿鱼 · 2007-07-11 · via 博客园 - 鱿鱼

private static string MyConnString = ConfigurationManager.AppSettings["SqlConnectionString"].ToString();
    SqlConnection MyConn;

    
int PageSize, RecordCount, PageCount, CurrentPage;

    
protected void Page_Load(object sender, EventArgs e)
    
{
        
//设定PageSize 
        PageSize = 6;
        MyConn 
= new SqlConnection(MyConnString);
        MyConn.Open();
        
//第一次请求执行 
        if (!Page.IsPostBack)
        
{

            CurrentPage 
= 0;
            ViewState[
"PageIndex"= 0;
            
//计算总共有多少记录
            RecordCount = CalculateRecord();
            lblRecordCount.Text 
= RecordCount.ToString();
            
//计算总共有多少页 
            if (RecordCount < PageSize)
                PageCount 
= 1;

            
if (RecordCount % PageSize == 0)
                PageCount 
= RecordCount / PageSize;

            
else
                PageCount 
= RecordCount / PageSize + 1;

            lblPageCount.Text 
= PageCount.ToString();
            ViewState[
"PageCount"= PageCount;

            ListBind();
        }

    }


    
//计算总共有多少条记录 
    public int CalculateRecord()
    
{
        
int intCount;
        
string strCount = "select count(*) as co from album where album_UserId=" + Convert.ToInt32(Session["user_Id"]);
        SqlCommand MyComm 
= new SqlCommand(strCount, MyConn);
        SqlDataReader dr 
= MyComm.ExecuteReader();
        
if (dr.Read())
        
{
            intCount 
= Int32.Parse(dr["co"].ToString());
        }

        
else
        
{
            intCount 
= 0;
        }

        dr.Close();
        
return intCount;
    }


    ICollection CreateSource()
    
{
        
int StartIndex;

        
//设定导入的起终地址 
        StartIndex = CurrentPage * PageSize;
        
string strSel = "select * from album where album_UserId=" + Convert.ToInt32(Session["user_Id"]);
        DataSet ds 
= new DataSet();

        SqlDataAdapter MyAdapter 
= new SqlDataAdapter(strSel, MyConn);
        MyAdapter.Fill(ds, StartIndex, PageSize, 
"album");

        
return ds.Tables["album"].DefaultView;
    }


    
public void ListBind()
    
{
        
this.ibtnPrev.ImageUrl = "~/userImg/toolbarMovePrev.gif";
        
this.ibtnNext.ImageUrl = "~/userImg/toolbarMoveNext.gif";
        
this.DataList1.DataSource = CreateSource();
        
this.DataList1.DataBind();

        
this.ibtnNext.Enabled = true;
        
this.ibtnPrev.Enabled = true;
        
if (CurrentPage == PageCount-1)
        
{
            
this.ibtnNext.ImageUrl = "~/userImg/toolbarMoveNextDisabled.gif";
            
this.ibtnNext.Enabled = false;
        }

        
if (CurrentPage == 0)
        
{
            
this.ibtnPrev.ImageUrl = "~/userImg/toolbarMovePrevDisabled.gif";
            
this.ibtnPrev.Enabled = false;
        }

        lblCurrentPage.Text 
= (CurrentPage+1).ToString();

    }


    
public void Page_OnClick(Object sender, CommandEventArgs e)
    
{
        CurrentPage 
= (int)ViewState["PageIndex"];
        PageCount 
= (int)ViewState["PageCount"];

        
string cmd = e.CommandName;
        
//判断cmd,以判定翻页方向 
        switch (cmd)
        
{
            
case "next":
                
if (CurrentPage < PageCount-1)
                    CurrentPage
++;
                
break;
            
case "prev":
                
if (CurrentPage > 0)
                    CurrentPage
--;
                
break;
        }


        ViewState[
"PageIndex"= CurrentPage;

        ListBind();

    }

html页面按钮代码中要加入:
<asp:ImageButton ID="ibtnNext" runat="server" CommandName="next" ImageUrl="~/userImg/toolbarMoveNext.gif"
                                            OnCommand="Page_OnClick" />