在DataList中添加分页 [英] Add Paging In a DataList

查看:136
本文介绍了在DataList中添加分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过很多关于在每次尝试一些代码时添加分页到数据列表的不同文章我似乎得到了不同的错误。希望有人可以告诉我添加或更改我的代码以使其工作。



我的aspx



I have looked at alot of different article regarding adding paging to a data list everytime i try some of the code i seem to get different errors. Hopefully someone can tell me what to add or change from my code to make this work.

My aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Debug="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
    <style type="text/css">
        .style1 {
            width: 100%;
        }
        .style2
        {
            width: 1005px;
            height: 0;
        }
    </style>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
    
        <table class="style1"  runat="server" id="table1" cellpadding="0" 

            cellspacing="0">
            <tr>
                <td bgcolor="#6699FF" colspan="2">
                     </td>
            </tr>
            <tr>
                <td>
                     </td>
                <td>
                     </td>
            </tr>
        </table>
    
    </div>
    <table cellpadding="0" cellspacing="0" class="style2" width="100%">
        <tr>
            <td>
                <asp:DataList ID="DataList1" runat="server" RepeatColumns ="3">
                    <ItemTemplate>
                    <table>
                        <tr>
                            <td>
                            
                        
                    BPID : <%# DataBinder.Eval(Container.DataItem, "BPID") %> 
  
                            </td>
                                
                        </tr>
                        <tr>
                            <td>
                            Status : <%# DataBinder.Eval(Container.DataItem, "Status") %>
    
                            </td>
                        </tr>
                    
                         </table>
                    </ItemTemplate>

                </asp:DataList>
                </td>
        </tr>
    </table>
    </form>
    </body>
</html>





我的C#





My C#

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Collections;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text.RegularExpressions;
using System.Threading;
using System.Net.Mail;

public partial class _Default : System.Web.UI.Page
{
    PagedDataSource pds = new PagedDataSource();

    protected void Page_Load(object sender, EventArgs e)
    {

        SqlConnection cs = new SqlConnection(@"Server=120-ASQL1-P-001.ABCD.LOCAL;Initial Catalog=AIM;User ID=USER;Password=PASS");

        SqlCommand cmd = new SqlCommand("SELECT * from interface1", cs);

        PagedDataSource pg = new PagedDataSource();

        cmd.CommandType = CommandType.Text;

        cmd.Connection = cs;

        cs.Open();

        DataList1.DataSource = cmd.ExecuteReader();

        DataList1.DataBind();

        cs.Close();
   
   }


 
}





I已经看到其他人使用数据表来完成这项工作的地方,但我从来没有真正使用过数据表,也不确定我理解这个概念。请帮忙!



I have seen where other people have used a datatable to make this work, but i have never really used a datatable and not sure that i understand the concept. Please help!

推荐答案

这些都是客户端分页。为了真正利用分页功能,您必须在服务器端执行此操作。手段页面应该从数据库中获取有限数量的记录。



查看此链接



http://activeengine.net/2010/12/19/how-to-create- server-side-paging-for-datatables-net-with-asp-net / [ ^ ]



你也可以使用服务器端分页C#进行谷歌
These are all client side paging. In order to truely utilizing the power of paging you have to do it on server side. Means page should get limited number of records from the database.

Check this link

http://activeengine.net/2010/12/19/how-to-create-server-side-paging-for-datatables-net-with-asp-net/[^]

You can also do google using "Server Side Paging C#"


DataList的自定义分页 [ ^ ]



使用ASP.NET 2.0中的Datalist Control实现高效的数据分页 [ ^ ]


这篇关于在DataList中添加分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆