Click here to Skip to main content
15,885,890 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

ASP.NET
<%@ 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>


My C#

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 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!
Posted

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#"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900