| |

VerySource

 Forgot password?
 Register
Search
View: 748|Reply: 7

Pagination of the Repeater control?

[Copy link]

3

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-3-4 00:00:02
| Show all posts |Read mode
There are many pages on the Repeater control, but they are paged when the page loads, as in the following example:
 
<% @ Page Language = "C #"%>
<% @ import namespace = "System.Data"%>
<% @ import namespace = "System.Data.OleDb"%>
<script language = "C #" runat = "server">
public void Page_Load (Object src, EventArgs e) {
  OleDbConnection objConn = new OleDbConnection ("Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" +
   Server.MapPath ("../ aspxWeb.mdb"));
  OleDbDataAdapter objCommand = new OleDbDataAdapter ("select * from Document", objConn);
  DataSet ds = new DataSet ();
  objCommand.Fill (ds);

  PagedDataSource objPds = new PagedDataSource ();
  objPds.DataSource = ds.Tables [0] .DefaultView;
  objPds.AllowPaging = true;
  objPds.PageSize = 5;
  int CurPage;
  if (Request.QueryString ["Page"]! = null)
    CurPage = Convert.ToInt32 (Request.QueryString ["Page"]);
  else
    CurPage = 1;

  objPds.CurrentPageIndex = CurPage-1;
  lblCurrentPage.Text = "Current page:" + CurPage.ToString ();

  if (! objPds.IsFirstPage)
    lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "? Page =" + Convert.ToString (CurPage-1);

  if (! objPds.IsLastPage)
    lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "? Page =" + Convert.ToString (CurPage + 1);

  Repeater1.DataSource = objPds;
  Repeater1.DataBind ();
}
</ script>
<html>
<head>
<title> Example of Repeater Control Pagination </ title>
<meta http-equiv = "Content-Type" content = "text / html; charset = gb2312">
<style>
  P, TD, DIV, SPAN {font-size: 9pt}
</ style>
</ head>
<body>
<form name = "form1" method = "POST" runat = "server">
<div style = "padding: 5px; background-color: #dedede">
<asp: label ID = "lblCurrentPage" runat = "server"> </ asp: label> </ td>
  <td>&nbsp; <asp: HyperLink id = "lnkPrev" runat = "server"> Previous page </ asp: HyperLink>
  <asp: HyperLink id = "lnkNext" runat = "server"> Next page </ asp: HyperLink>&nbsp;
</ div>
<hr size = "1" color = "# 000099" />
<asp: Repeater ID = "Repeater1" runat = "server">
<Itemtemplate>
<div style = "padding: 5px; background-color: #dedede">
<% # DataBinder.Eval (Container.DataItem, "Title")%>
</ div>
</ Itemtemplate>
</ asp: Repeater>
</ form>
</ body>
</ html>

In practical applications, they are based on a certain event (such as a query). If the above example is rewritten as Repeater paging based on a certain query event?
Reply

Use magic Report

3

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-5-17 08:30:01
| Show all posts
The main problem is that after querying, pagination, click the next page Repeater will not display the data
Reply

Use magic Report

1

Threads

9

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-5-18 08:30:02
| Show all posts
It will be better to use stored procedures ~!
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-5-18 09:15:01
| Show all posts
After the query, the data after the query must be bound again
Reply

Use magic Report

0

Threads

20

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-5-18 11:15:02
| Show all posts
If you directly change your code

You just copy these codes into a new method, pass the sql statement as a parameter, and execute it once every page refresh

One more word, this code has poor performance
Reply

Use magic Report

0

Threads

20

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-5-18 16:00:01
| Show all posts
Write code for you
public void ExecuteSQL (string sql) {
  OleDbConnection objConn = new OleDbConnection ("Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" +
   Server.MapPath ("../ aspxWeb.mdb"));
  OleDbDataAdapter objCommand = new OleDbDataAdapter (sql, objConn);
  DataSet ds = new DataSet ();
  objCommand.Fill (ds);

  PagedDataSource objPds = new PagedDataSource ();
  objPds.DataSource = ds.Tables [0] .DefaultView;
  objPds.AllowPaging = true;
  objPds.PageSize = 5;
  int CurPage;
  if (Request.QueryString ["Page"]! = null)
    CurPage = Convert.ToInt32 (Request.QueryString ["Page"]);
  else
    CurPage = 1;

  objPds.CurrentPageIndex = CurPage-1;
  lblCurrentPage.Text = "Current page:" + CurPage.ToString ();

  if (! objPds.IsFirstPage)
    lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "? Page =" + Convert.ToString (CurPage-1);

  if (! objPds.IsLastPage)
    lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "? Page =" + Convert.ToString (CurPage + 1);

  Repeater1.DataSource = objPds;
  Repeater1.DataBind ();
}

public void Page_Load (Object src, EventArgs e)
{
    this.ExecuteSQL ("select * from Document");
}

lz then change the control of the page number by yourself
Reply

Use magic Report

3

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-5-20 09:45:01
| Show all posts
Write the Page_Load part of the above example to the Button_Click event. Although it is also paginated, there will be no data in the Repeater when you click the next page.
Reply

Use magic Report

2

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-5-22 21:45:01
| Show all posts
I feel like this kind of page that just displays data, you can use the custom http handler to bypass the asp.net page frame processing, use the dataset to generate xml memory stream-convert it into a string stream, and then use the write method of httptextwriter Network streaming. At this time, you can use the client data island to bind the table method to achieve client paging. Together with the use of CSS\Javascrit. Of course, all this work is done in ProcessRequest.
------ Because all the data is cached in the client ie, it is very friendly to the user, and it also reduces the burden on the server.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list