Intimate contact asp.net (11)

Source: Internet
Author: User
Tags join
asp.net in asp.net, how to do pagination

I have been asked more than once about how to implement paging functionality in ASP.net. I really do not want to answer this question.
Because in the asp.net to achieve pagination, it is too simple, simple to see the program will go to the gas jump, ah
Ah to publish sigh, why this dongdong not early out.

In the live web technology, we want to do pagination, often a long string of code to get it done, and each page
Face, it is necessary to rewrite once, annoying the deadly. But with the DataGrid control in ASP.net, our paging program can
Easy to handle, just need to make some settings for the DataGrid control. We are still using a program to see:

<% @ Page language= "C #"%>
<% @ Import namespace= "System.Data"%>
<% @ Import namespace= "System.Data.ADO"%>
<script language= "C #" runat= "Server" >
public void Page_Load (Object Src,eventargs E)
{
Join statement
String myConnString = "Driver={microsoft Access Driver (*.mdb)};
Dbq=c:/test/test.mdb; ";
String Strcomm = "SELECT * from userlist order by id";

Open a Join
ADOConnection myconnection = new ADOConnection (myConnString);

Open two DataSetCommand
Adodatasetcommand Mycomm = new Adodatasetcommand (strcomm,myconnection);


DataSet myDataSet = new DataSet ();

Save a userlist,booklist table in a dataset
Mycomm.filldataset (myDataSet, "userlist");


DataGrid1.DataSource = mydataset.tables["UserList"]. DefaultView;
Datagrid1.databind ();

}
</script>
<title></title>
<body>
<form runat= "Server" >
<asp:datagrid id= "DATAGRID1" runat= "Server"
Bordercolor= "BLACK"
Borderwidth= "1"
Gridlines= "Both"
Cellpadding= "3"
cellspacing= "0"
Font-name= "Verdana"
Font-size= "8pt"
Headerstyle-backcolor= "#aaaadd"
Alternatingitemstyle-backcolor= "#eeeeee"
/>
</form>
</body>

Its display results are:


Figure 11-1

You can see that 11 of the data in this userlist table are all out, no paging.

Now let's change the properties of the DataGrid control. Plus

Allowpaging= "True"
Pagesize= "5"
Pagerstyle-horizontalalign= "Right"

Look again:


Figure 11-2

Look at the bottom of the picture, is not more, is not, this means pagination, we go to press that tag can
See the next page:


Figure 11-4

It's all too easy. Oh. Their source is just that I added the three attributes. In fact, as long as a allow
Paging on the line.

AllowPaging refers to allowing paging, which is the most important. With it, we can be divided into pages.

PAGESIZE specifies the number of records to display per page, and if not, the default is 10.

Pagerstyle-horizontalalign is the location that specifies the faceted display, and the default is left.

All code is:

<asp:datagrid id= "DATAGRID1" runat= "Server"
Allowpaging= "True"
Pagesize= "5"
Pagerstyle-horizontalalign= "Right"
Bordercolor= "BLACK"
Borderwidth= "1"
Gridlines= "Both"
Cellpadding= "3"
cellspacing= "0"
Font-name= "Verdana"
Font-size= "8pt"
Headerstyle-backcolor= "#aaaadd"
Alternatingitemstyle-backcolor= "#eeeeee"
/>
 

is not very simple. Oh.

Note that when writing this do not forget <form>, otherwise your page is able to show, but can not turn, hehe. Because this is
To be submitted:)

The next section, we will explain more detailed content, hehe, mainly considering the picture too much. The browsing speed slows down.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.