asp.net repeater 数字分页代码

asp教程.net repeater 数字分页代码
public static string sort { set; get; }
    private static string strsql;
    sqlconnection con = new sqlconnection("server=localhost;database=moldsystem;uid=sa;pwd=sa");//这个是全局变量
   
    private pageddatasource pds()
    {
        if (textbox4.text != "")
        {
            string a = textbox4.text;
            strsql = "select * from data_mold where customer_name='" + a + "'";
            dataset ds = new dataset();
            sqldataadapter sda = new sqldataadapter(strsql, con);
            sda.fill(ds, "name");
            pageddatasource pds = new pageddatasource();
            pds.datasource = ds.tables["name"].defaultview;
            pds.allowpaging = true;//允许分页
            pds.pagesize = 2;//单页显示项数
            pds.currentpageindex = convert.toint32(request.querystring["page"]);
            return pds;
        }
        else
        {
            strsql = "select * from data_mold";
            dataset ds = new dataset();
            sqldataadapter sda = new sqldataadapter(strsql, con);
            sda.fill(ds, "name");
            pageddatasource pds = new pageddatasource();
            pds.datasource = ds.tables["name"].defaultview;
            pds.allowpaging = true;//允许分页
            pds.pagesize = 2;//单页显示项数
            pds.currentpageindex = convert.toint32(request.querystring["page"]);
            return pds;
        }
    }
    protected void ddlp_selectedindexchanged(object sender, eventargs e)
    {//脚模板中的下拉列表框更改时激发
        string pg = convert.tostring((convert.toint32(((dropdownlist)sender).selectedvalue) - 1));//获取列表框当前选中项
        response.redirect("default2.aspx?page=" + pg);//页面转向
    }
protected void page_load(object sender, eventargs e)
    {
        if (!ispostback)
        {
            repeater1.datasource = pds();
            repeater1.databind();   
        }
    }
 protected void repeater1_itemcommand(object source, repeatercommandeventargs e)
    {

    }
    protected void repeater1_itemdatabound(object sender, repeateritemeventargs e)
    {
        if (e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem)
        {
            for (int i = 0; i < e.item.controls.count; i++)
            {
                control control = e.item.controls[i];
                getcontrol(control);
            }
        }
        if (e.item.itemtype == listitemtype.footer)
        {
            dropdownlist ddlp = (dropdownlist)e.item.findcontrol("ddlp");

            hyperlink lpfirst = (hyperlink)e.item.findcontrol("hlfir");
            hyperlink lpprev = (hyperlink)e.item.findcontrol("hlp");
            hyperlink lpnext = (hyperlink)e.item.findcontrol("hln");
            hyperlink lplast = (hyperlink)e.item.findcontrol("hlla");

            pds().currentpageindex = ddlp.selectedindex;

            int n = convert.toint32(pds().pagecount);//n为分页数
            int i = convert.toint32(pds().currentpageindex);//i为当前页

            label lblpc = (label)e.item.findcontrol("lblpc");
            lblpc.text = n.tostring();
            label lblp = (label)e.item.findcontrol("lblp");
            lblp.text = convert.tostring(pds().currentpageindex + 1);

            if (!ispostback)
            {
                for (int j = 0; j < n; j++)
                {
                    ddlp.items.add(convert.tostring(j + 1));
                }
            }

            if (i <= 0)
            {
                lpfirst.enabled = false;
                lpprev.enabled = false;
                lplast.enabled = true;
                lpnext.enabled = true;
            }
            else
            {
                lpprev.navigateurl = "?page=" + (i - 1);
            }
            if (i >= n - 1)
            {
                lpfirst.enabled = true;
                lplast.enabled = false;
                lpnext.enabled = false;
                lpprev.enabled = true;
            }
            else
            {
                lpnext.navigateurl = "?page=" + (i + 1);
            }

            lpfirst.navigateurl = "?page=0";//向本页传递参数page
            lplast.navigateurl = "?page=" + (n - 1);

            ddlp.selectedindex = convert.toint32(pds().currentpageindex);//更新下拉列表框中的当前选中页序号
        }

    }
    protected void getcontrol(control control)
    {
        foreach (control c in control.controls)
        {

            if (c.hascontrols())
            {
                getcontrol(c);
            }
            else
            {
                if (c.gettype().tostring() == "system.web.ui.webcontrols.textbox")
                {
                    textbox txt = c as textbox;
                    txt.attributes.add("onclick", "write('" + txt.clientid + "');");//双击时是ondblclick
                    txt.attributes.add("onblur", "update('" + txt.clientid + "');");
                }
            }
        }
    }
    protected void button1_click(object sender, eventargs e)
    {
        repeater1.datasource = pds();
        repeater1.databind();
    }

时间: 2024-09-20 00:44:52

asp.net repeater 数字分页代码的相关文章

Asp.NET 的aspnetpager分页代码

asp教程.net 的aspnetpager分页代码  @ page language="c#" autoeventwireup="true" codefile="default.aspx.cs" inherits="test_default" stylesheettheme="default" %> <%...@ register assembly="aspnetpager"

一个asp.net MVC 的分页代码

哈哈,这个博客的处女文啦~~ 首先声明,这个分页代码并不是出自我手哈,借用了网上的一段代码,然后加了个css,变的好看一些啦~~ 原作者忘记是谁了,实在找不到了--万分抱歉啊~~ 效果如下:     1 using System; 2  using System.Collections.Generic; 3  using System.Linq; 4  using System.Web; 5  using System.Web.Mvc; 6  using System.Web.Routing;

asp.net C# 存储过程分页代码

 代码如下 复制代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace opdata {     pub

asp.net利用存储过程分页代码

下面是存储过程(sqlserver2000下通过)   --最通用的分页存储过程 -- 获取指定页的数据  CREATE PROCEDURE Pagination  @tblName   varchar(255),       -- 表名  @strGetFields varchar(1000) = ''*'',  -- 需要返回的列  @fldName varchar(255)='''',      -- 排序的字段名  @PageSize   int = 10,          -- 页尺

asp.net sql存储过程分页代码

use [data_smf] go /****** 对象:  storedprocedure [dbo].[catsearch]    脚本日期: 01/23/2011 04:34:30 ******/ set ansi_nulls on go set quoted_identifier on go -- ============================================= -- author:        <author,,name> -- create date:

分页代码_ASP基础

分页代码: <%''本程序文件名为:Pages.asp%> <%''包含ADO常量表文件adovbs.inc,可从"\Program Files\Common Files\System\ADO"目录下拷贝%> <!--#Include File="adovbs.inc"--> <%''*建立数据库连接,这里是Oracle8.05数据库 Set conn=Server.CreateObject("ADODB.Conn

ASP 数字分页效果代码_应用技巧

最近网站改版正好发现原来的分页不带数字的,只有首页 上页 下页 末页 然后是select的跳转,都是以前比较流行的,而现在比较流行的是数字分页在中间,正好研究并分享下,需要的朋友可以参考下 效果: 国外的核心代码: 复制代码 代码如下: <% 'digg style pagination script in asp.. written by Moazam... http://www.moazam.com/2007/03/30/asp-digg-style-pagination-script/  

ASP 数字分页效果代码

最近网站改版正好发现原来的分页不带数字的,只有首页 上页 下页 末页 然后是select的跳转,都是以前比较流行的,而现在比较流行的是数字分页在中间,正好研究并分享下,需要的朋友可以参考下 效果: 国外的核心代码: 复制代码 代码如下:<% 'digg style pagination script in asp.. written by Moazam... http://www.moazam.com/2007/03/30/asp-digg-style-pagination-script/ fu

在ASP.NET 2.0中操作数据之四十一:DataList和Repeater数据分页_自学过程

导言 分页和排序是显示数据时经常用到的功能.比如,在一个在线书店里搜索关于ASP.NET 的书的时候,可能结果会是成百上千,而每页只列出十条.而且结果可以根据title(书名),price(价格),page count(页数),author name(作者)等来排序.我们在分页和排序报表数据 里已经讨论过, GridView, DetailsView, 和FormView 都有内置的分页功能,仅仅只需要勾一个checkbox就可以开启.GridView 还支持内置的排序. 不幸的是,DataLi