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

推荐订阅源

F
Fortinet All Blogs
Attack and Defense Labs
Attack and Defense Labs
V2EX - 技术
V2EX - 技术
O
OpenAI News
S
Secure Thoughts
H
Heimdal Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Schneier on Security
Schneier on Security
H
Hacker News: Front Page
S
Security Affairs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
The Register - Security
The Register - Security
GbyAI
GbyAI
Cloudbric
Cloudbric
MongoDB | Blog
MongoDB | Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Forbes - Security
Forbes - Security
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Cloudflare Blog
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Webroot Blog
Webroot Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
T
Tor Project blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
V
V2EX
T
Tailwind CSS Blog
SecWiki News
SecWiki News
NISL@THU
NISL@THU
C
Check Point 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" />