DataList控件分页

实现了对DataList的分页 HTML控件的值需要转换web应用程序就可以取到了 
ContractedBlock.gifExpandedBlockStart.gif
  1ExpandedBlockStart.gifContractedBlock.gif /**//// <summary>
  2        /// 当前页数
  3        /// </summary>

  4        int CurrentPage;
  5ExpandedBlockStart.gifContractedBlock.gif        /**//// <summary>
  6        /// 每页条数
  7        /// </summary>

  8        int PageSize;
  9ExpandedBlockStart.gifContractedBlock.gif        /**//// <summary>
 10        /// 总页数
 11        /// </summary>

 12        int PageCount;
 13ExpandedBlockStart.gifContractedBlock.gif        /**//// <summary>
 14        /// 总条数
 15        /// </summary>

 16        int RecordCount;
 17
 18ExpandedBlockStart.gifContractedBlock.gif        /**//// <summary>
 19        /// 页面首次加载
 20        /// </summary>
 21        /// <param name="sender">发送对象</param>
 22        /// <param name="e">事件参数</param>

 23        protected void Page_Load(object sender, EventArgs e)
 24ExpandedBlockStart.gifContractedBlock.gif        {
 25            PageSize = 2;//每页数据记录
 26
 27            if (!IsPostBack)
 28ExpandedSubBlockStart.gifContractedSubBlock.gif            {
 29                CurrentPage = 0;//当前页习惯设为0
 30                ViewState["PageIndex"= 0;//页索引也设为0
 31
 32                //计算总共有多少记录
 33                RecordCount = CalculateRecord();
 34
 35                //计算总共有多少页
 36                if (RecordCount % PageSize == 0)
 37ExpandedSubBlockStart.gifContractedSubBlock.gif                {
 38                    PageCount = RecordCount / PageSize;
 39                }

 40                else
 41ExpandedSubBlockStart.gifContractedSubBlock.gif                {
 42                    PageCount = RecordCount / PageSize + 1;
 43                }

 44
 45                this.TotalLbl.Text = PageCount.ToString();//显示总页数
 46                ViewState["PageCount"= PageCount;
 47
 48                this.DataListBind();
 49            }

 50        }

 51
 52
 53ExpandedBlockStart.gifContractedBlock.gif        /**//// <summary>
 54        /// 计算记录数
 55        /// </summary>
 56        /// <returns></returns>

 57        private int CalculateRecord()
 58ExpandedBlockStart.gifContractedBlock.gif        {
 59            try
 60ExpandedSubBlockStart.gifContractedSubBlock.gif            {
 61                int recordCount;
 62                SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
 63                con.Open();
 64
 65                string sql = "select count(*) as count from cps_adinfo";
 66                SqlCommand cmd = new SqlCommand(sql, con);
 67                SqlDataReader sdr = cmd.ExecuteReader();
 68
 69                if (sdr.Read())
 70ExpandedSubBlockStart.gifContractedSubBlock.gif                {
 71                    recordCount = Int32.Parse(sdr["count"].ToString());
 72                }

 73                else
 74ExpandedSubBlockStart.gifContractedSubBlock.gif                {
 75                    recordCount = 0;
 76                }

 77
 78                sdr.Close();
 79                con.Close();
 80
 81                return recordCount;
 82            }

 83
 84            catch (Exception ex)
 85ExpandedSubBlockStart.gifContractedSubBlock.gif            {
 86                throw new Exception(ex.Message);
 87            }

 88        }

 89
 90
 91ExpandedBlockStart.gifContractedBlock.gif        /**//// <summary>
 92        /// 将数据绑定到Datalist控件
 93        /// </summary>

 94        public void DataListBind()
 95ExpandedBlockStart.gifContractedBlock.gif        {
 96            try
 97ExpandedSubBlockStart.gifContractedSubBlock.gif            {
 98                int StartIndex = CurrentPage * PageSize;//设定导入的起终地址
 99
100                string sql = "select * from cps_adinfo";
101
102                DataSet ds = new DataSet();
103                SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString());
104                con.Open();
105
106                SqlDataAdapter sda = new SqlDataAdapter(sql, con);
107                //Fill方法的第一次重载
108                sda.Fill(ds, StartIndex, PageSize, "cps_adinfo");
109
110                this.TextDataList.DataSource = ds.Tables["cps_adinfo"].DefaultView;
111                this.TextDataList.DataBind();
112                this.PreviousLB.Enabled = true;
113                this.NextLB.Enabled = true;
114                if (CurrentPage == (PageCount - 1)) this.NextLB.Enabled = false;//当为最后一页时,下一页链接按钮不可用
115                if (CurrentPage == 0this.PreviousLB.Enabled = false;//当为第一页时,上一页按钮不可用
116                this.CurrentLbl.Text = (CurrentPage + 1).ToString();//当前页数
117
118            }

119
120            catch (Exception ex)
121ExpandedSubBlockStart.gifContractedSubBlock.gif            {
122                throw new Exception(ex.Message);
123            }

124        }

125
126ExpandedBlockStart.gifContractedBlock.gif        /**//// <summary>
127        /// 按钮点击事件
128        /// </summary>
129        /// <param name="sender"></param>
130        /// <param name="e"></param>

131        public void LinkButton_Click(Object sender, CommandEventArgs e)
132ExpandedBlockStart.gifContractedBlock.gif        {
133            CurrentPage = Int32.Parse(ViewState["PageIndex"].ToString());//获得当前页索引
134            PageCount = Int32.Parse(ViewState["PageCount"].ToString());//获得总页数
135
136            string cmd = e.CommandName; //判断cmd,以判定翻页方向
137            switch (cmd)
138ExpandedSubBlockStart.gifContractedSubBlock.gif            {
139                case "prev"://上一页
140                    if (CurrentPage > 0) CurrentPage--;
141                    break;
142
143                case "next":
144                    if (CurrentPage < (PageCount - 1)) CurrentPage++;//下一页
145                    break;
146
147                case "first"://第一页
148                    CurrentPage = 0;
149                    break;
150
151                case "end"://最后一页
152                    CurrentPage = PageCount - 1;
153                    break;
154
155                case "jump"://跳转到第几页
156                    if (this.TextBox1.Value.Trim() == ""
157                        || Int32.Parse(this.TextBox1.Value.Trim()) > PageCount
158                        || Int32.Parse(this.TextBox1.Value.Trim()) == 0)
159                      
160ExpandedSubBlockStart.gifContractedSubBlock.gif                    {
161                        return;
162                    }

163                    else
164ExpandedSubBlockStart.gifContractedSubBlock.gif                    {
165                        CurrentPage = Int32.Parse(this.TextBox1.Value.ToString()) - 1;
166                        break;
167                    }

168            }

169            ViewState["PageIndex"= CurrentPage;//获得当前页
170            this.DataListBind();
171            
172        }
  

分页跳转时做了判断 不会报异常了
下面是设计页
ContractedBlock.gifExpandedBlockStart.gifCode
 1  <asp:DataList ID="TextDataList" runat="server" Width="100%" DataKeyField="adid" EnableViewState="False"
 2                    CssClass="pic" Font-Overline="False">
 3                    <ItemTemplate>
 4                        <class="piczt">
 5                            文字链内容:
 6                            <asp:Label ID="lal" runat="server" Text='<%# Eval("adtitle") %>'></asp:Label><br />
 7                        </p>
 8                                               <div class="picco">
 9                            <class="picco1">
10                                 <asp:TextBox ID="txtHtmlCode" TextMode="MultiLine" Rows="3" Columns="40" Text='<%# Eval("htmlcode") %>'
11                                            runat="server" ReadOnly="true" EnableViewState="false"></asp:TextBox>
12                            </p>
13                            <class="picco2">
14                                <asp:TextBox ID="txtForumCode" TextMode="MultiLine" Rows="3" Columns="40" Text='<%# Eval("forumcode") %>'
15                                            runat="server" ReadOnly="true" EnableViewState="false"></asp:TextBox>
16                             </p>
17                        </div>
18                        <div class="picco">
19                            <class="picco1">
20                             <input name="button1" type="button"  class="an2" value="复制广告代码" onclick="setTxt('<%# Eval("htmlcode") %>')"/>
21                                    复制广告代码</button>
22                            </p>
23                            <class="picco2">
24                                <input name="button1" type="button" class="an2" value="复制论坛代码" onclick="setTxt('<%# Eval("forumcode") %>')"/>
25                                    复制论坛代码</button>
26                            </p>
27                        </div>
28                        <class="piczt">
29                            产品名称:鞋 产品ID:123456789</p>
30                        <class="piczt">
31                            提成比例:10%</p>
32                        <class="piczt">
33                            <span class="zi2">注意:</span> 您的联盟 ID, abcdef , 已经包含在代码中</p>
34                    </ItemTemplate>
35                    <ItemStyle Width="100%" />
36                </asp:DataList>
37                <div class="page">
38                    共<asp:Label ID="TotalLbl" runat="server"></asp:Label>页, 当前第<asp:Label ID="CurrentLbl"
39                        runat="server"></asp:Label>
40                    <asp:LinkButton ID="FirstLB" runat="server" OnCommand="LinkButton_Click" CommandName="first"
41                        Font-Overline="False">[ 首页 | </asp:LinkButton>
42                    <asp:LinkButton ID="PreviousLB" runat="server" OnCommand="LinkButton_Click" CommandName="prev"
43                        Font-Overline="False">上一页 | </asp:LinkButton>
44                    <asp:LinkButton ID="NextLB" runat="server" OnCommand="LinkButton_Click" CommandName="next"
45                        Font-Overline="False">下一页 | </asp:LinkButton>
46                    <asp:LinkButton ID="EndLB" runat="server" OnCommand="LinkButton_Click" CommandName="end"
47                        Font-Bold="False" Font-Overline="False">末页 ]</asp:LinkButton>
48                    <asp:LinkButton ID="JumpLB" runat="server" OnCommand="LinkButton_Click" CommandName="jump"
49                        Font-Overline="False">跳到</asp:LinkButton>
50                    <input id="TextBox1" runat="server" type="text" name="TextBox1" style="width: 30px"
51                        onkeyup="value=value.replace(/[^\d]/g,'')" />
52                </div>
53
54
功能上除了分页 还有一个复制文本框的方法
    <script type="text/javascript">
        function setTxt(obj) {
            window.clipboardData.setData('text', obj);
            alert("复制成功!");
        }
    </script>

转载于:https://www.cnblogs.com/uranuschen/archive/2009/07/21/1527833.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/381277.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

现代php 阅读笔记,PHP 手册阅读笔记 - 语言参考篇

最近计划把 PHP手册&#xff0c;认真的先过一遍。记录一些以前不知道&#xff0c;不明确的知识。语言参考 > 类型【新认知】强制转换类型用 settype( mixed $var, string $type )。判断变量的类型用is_type函数。例如&#xff1a;if (is_int($an_int)) {$an_int 4;}if (is_…

mongodb连接失败_mongodb 数据库及数据分页

本文转载于 SegmentFault 社区作者&#xff1a;小小蚊子在做自己的一个小项目时&#xff0c;新学习了 mongodb非关系型数据库&#xff0c;使用了 mongoose封装好的查询方法&#xff0c;包括数据库分页用到的limit和 skip 方法&#xff0c;这里记录下。一mongodb 数据库连接参照…

python 去除空格和换行,删除空格和换行符-BeautifulSoup Python

使用Beautifulsoup&#xff0c;我正在抓取以下Web源&#xff1a;Manchester Citys Fabian Delph limped off in the first minute of England Euro 2016 qualifier against Switzerland with a suspected hamstring injury. The 25-year-old midfielder, who signed for City f…

Windows MobileCE 开发书籍大全

1、《Microsoft Windows CE 程序设计》 北京大学出版社[美]Doudlas Boling 著该书可以与经典著作《Microsoft Windows 程序设计》相媲美&#xff0c;就象要想在Window平台上开发&#xff0c;必看 《Microsoft Windows 程序设计》一样&#xff0c;如果你想在Windows CE平台上开发…

python自动答题助手_GitHub - SmileSmith/autoAnswer: 客户端答题工具,集成3个答题助手,包含AI自动答题,手动答题,adb控制多台手机等...

autoAnswer和简单搜索、汪仔助手、UC答题助手一起答题。支持AI自动答题&#xff0c;支持个性化题。注&#xff1a;近期各个答题助手都升级了安全策略&#xff0c;如有问题请随时反馈 ~ ~**AI自动答题的详细流程说明请打开(见图)AI自动答题的结果预览(见图)答题界面见预览&#…

php ajax json post请求参数传递,javascript - ajax post 有个请求参数要用json 但请问js怎么转json的?...

$.ajax({url: linkAndBindUrl,method: post,data: {key: "web",toKen: toKen,memberId: memberId,json:, //[{"id":1,"appellation":"爸爸"},{"id":2,"appellation":"爷爷"}],beMemberId: beMemberId},…

创建数据类的原则

转载于:https://www.cnblogs.com/ghostbox/archive/2009/08/03/2251083.html

mysql 关联查询_Mysql查询优化器,再也不会因为该什么时候建立索引发愁了

优化器的作用&#xff1a;我们知道&#xff0c;一条SQL语句&#xff0c;可以有很多执行方式&#xff0c;最后都返回相同的结果&#xff0c;而优化器的作用就是找到最好的执行计划。一、RBO-基于规则的优化器(rule)系统内置的一套硬编码规则&#xff0c;根据规则生成执行计划&am…

购物车的收货地址js php,Javascript实现购物车功能的详细代码

我们肯定都很熟悉商品购物车这一功能&#xff0c;每当我们在某宝某东上购买商品的时候&#xff0c;看中了哪件商品&#xff0c;就会加入购物车中&#xff0c;最后结算。购物车这一功能&#xff0c;方便消费者对商品进行管理&#xff0c;可以添加商品&#xff0c;删除商品&#…

CLI下的网页浏览器之二——Lynx

出自&#xff1a;http://vb2005xu.javaeye.com/blog/230044 Lynx浏览器使用指南 Lynx是一个字符界面下的全功能的WWW浏览器。Lynx 可以运行在很多种操作系统下&#xff0c;如VMS, UNIX, Windows 95, Windows NT等&#xff0c;当然也包括Linux。 由于没有漂亮的图形界面&#xf…

python中减法运算函数_详解 Python 的二元算术运算,为什么说减法只是语法糖?...

原题| Unravelling binary arithmetic operations in Python作者| Brett Cannon译者| 豌豆花下猫(“Python猫”公众号作者)声明| 本翻译是出于交流学习的目的&#xff0c;基于 CC BY-NC-SA 4.0 授权协议。为便于阅读&#xff0c;内容略有改动。大家对我解读属性访问的博客文章反…

【SQL】DQL语句影响行数不能超过XX值

mysql执行临时查看添加limit 10 查询 select * from msg_info cc WHERE DATE_FORMAT(cc.CREATE_DATE,%Y%m%d) 20231127;> 1025 - [xx_dql_where]DQL语句需要增加where条件;[xx_dql_explain]DQL语句影响行数不能超过20000,当前值180906; > 时间: 0.021s处理 select * …

Oracle访问同义词连接超时,利用同义词解决oracle用户访问其它schema的对象

由于应用需要&#xff0c;aa能访问bb的所有表。SQL> create user aa identified by oracle;User created.SQL> grant connect,resource to aa;Grant succeeded.SQL> create user bb identified by oracle;User created.SQL> grant connect,resource to bb;Grant su…

一个不错的讲解flex 3中自定义事件的文章

一个不错的讲解flex 3中自定义事件的文章 http://wangyisong.javaeye.com/blog/376118&#xff0c;一个不错的讲解flex 3中自定义事件的文章posted on 2009-08-08 17:41 jackyrong的世界 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/jackyrong/archive/2009…

oracle同义,oracle同义词

搞了几天数据同步的程序&#xff0c;写完之后觉得很浪费&#xff0c;因为oracle自身的数据库联机备份功能已经相当强大。不过关键一点是我们应用场景跟联机备份有很大差别。虽然这次没用上oracle自身备份功能&#xff0c;但是有一个通过建立db link 来实现同步倒也很简单&#…

stm32 整数加法循环时间_【教学设计】小数加法教学设计

小数加法教学设计刘秀锦舞钢市特殊教育学校教材分析本节课是第四单元“小数加减法”的第一课时&#xff0c;小数加减法是以整数加减法为基础进行教学的&#xff0c;本节课走踏实了&#xff0c;后边的知识才能顺利的进行下去&#xff0c;所以本节课还是以小步走、学一点、练一点…

调用WindowsAPI显示帮助提示

导言 前一段时间&#xff0c;在编写程序的过程中&#xff0c;需要一个帮助功能按钮。这个按钮众所周知&#xff0c;按下按钮以后&#xff0c;鼠标变成带有问号的鼠标&#xff0c;然后点击画面上的控件&#xff0c;然后就回出现一个提示的文本&#xff0c;该处是什么含意。就好像…

python整形魔法_python 魔法方法

&#xff11;、什么是魔法方法&#xff1f;魔法方法就是可以给你的类增加魔力的特殊方法&#xff0c;如果你的对象实现(重载)了这些方法中的某一个&#xff0c;那么这个方法就会在特殊的情况下被 Python 所调用&#xff0c;你可以定义自己想要的行为&#xff0c;而这一切都是自…

oracle正则匹配全部,sql – 返回Oracle中正则表达式的所有匹配项

您已经提供了数据样本,说明这是一行,但已将其显示为两个不同的行.所以这个例子基于你的话.-- Sample of data from your question extra row for the sake of demonstration-- id column is added to distinguish the rows(I assume you have one)with t1(id, col) as(select …

hashtable,dictionary 从原理上说说有什么异同,哪个性能高一些

hashtable里存的对象全部是object类型 ,所有对象存进去都被转成object类型,读取出来每次都需要转换类型,hashtable对存入的类型没有限制 , 因此在读取转换类型时容易出错, dictionary只能存入定义时指定的类型,而且不像hashtable会把类型转换成object,存取起来比前者方便,效率更…