DOTNET implements a solution for turning pages by specified pages in WAP application development

Source: Internet
Author: User

Release date: 8/30/2005 update date: 8/30/2005

Panqi
Ultrapower Software

Introduction: WAP applications are developed using DOTNET. Page turning is usually encountered. Although the itemcount and itemsperpage attributes are provided in the list control of DOTNET to achieve page turning, however, this built-in page turning function can only achieve the page turning effect of "Previous Page" and "next page", and cannot selectively flip pages based on the specified number of pages. Therefore, it is necessary to develop your own page turning mechanism, to improve its shortcomings, this document describes how to use it step by step. NET provides limited mobilecontrol to achieve page flip by specified pages.

If you want to resend the post, keep the original source and do not delete it. Thank you.

 

Download source code>

Solution 1: Use Data Binding and specify a data source (able) to flip pages

Step 1: Open vs. NET and create an ASP. NET mobile Web application. Here we name the project wappager, for example:

 

 

Step 2: drag the required controls into the form:

Label control, one for displaying prompt messages.

List control. One is used to bind data and display records within the specified range.

Panel control, which is used to store the link pages of N pages calculated by the expression.

Shows the page layout:

 

 

 

Step 3: Modify the control attributes to prepare for encoding. (For details about attribute settings, see the demo ).

Step 4: encoding. (Description: The demo data is from the SQL-server's northwind database)

To achieve the page turning effect, you need to use the following three methods:

1. getalldata () method:

Getalldata is the method for obtaining all data and returning datatable. The reason why datatable is used to store all data is mainly to obtain records within the specified range using the select method of datatable;

Private datatable getalldata ()
{
This. sqldataadapter1.fill (this. dataset11 );
Return this. dataset11.tables ["Products"];
}
 

2. getpage () method:

Getpage calculates the number of pages based on the total number of data and the number of pages displayed on each page. It returns the datatable that stores all page numbers. We have defined two columns for this datatable: linktext and linkurl, the values of these two columns are used by the page control link to bind data.

Private datatable getpage ()
{
Datatable dtpage = new datatable ();
Datatable dtalldata = This. _ dtalldata;
Int datacount = dtalldata. Rows. count;
Int pagecount = 0;
If (datacount % globalconfig. Size) = 0)
{
Pagecount = datacount/globalconfig. size;
}
If (datacount % globalconfig. Size )! = 0)
{
Pagecount = datacount/globalconfig. Size + 1;
}
Dtpage. Columns. Add ("linktext", typeof (string ));
Dtpage. Columns. Add ("linkurl", typeof (string ));
For (INT I = 0; I <pagecount; I ++)
{
Datarow ROW = dtpage. newrow ();
Row ["linktext"] = I + 1;
If (I = 0)
{
Row ["linkurl"] = "mobilewebform1.aspx? Startid = "+ (I * globalconfig. Size) +" & selectpage = "+ I;
}
Else
{
Row ["linkurl"] = "mobilewebform1.aspx? Startid = "+ (I * globalconfig. Size) + 1) +" & selectpage = "+ I;
}
Dtpage. Rows. Add (ROW );
}
Return dtpage;
}
 

3. selecttable () method:

The selecttable method uses the select method of the datatable itself to pass in the starting value, read the records of the specified number of rows, and finally achieve page turning effect.
Private void selecttable (INT startid)
{
Try
{
Datatable dtalldata = This. _ dtalldata;
Datatable dtselectdata = new datatable ();
Dtselectdata. Columns. Add ("productid", typeof (string ));
Dtselectdata. Columns. Add ("productname", typeof (string ));
String strexpr;
Int endid = startid + globalconfig. size;
If (startid = 0)
{
Strexpr = "productid> =" + startid + "and productid <=" + endid + "";
}
Else
{
Strexpr = "productid> =" + startid + "and productid <" + endid + "";
}
If (dtalldata! = NULL & dtalldata. Rows. Count> 0)
{
Datarow [] foundrows = dtalldata. Select (strexpr );
String flag1 = foundrows. length. tostring ();
For (INT I = 0; I <foundrows. length; I ++)
{
Datarow ROW = dtselectdata. newrow ();
Row ["productid"] = foundrows [I] [0];
Row ["productname"] = foundrows [I] [1];
Dtselectdata. Rows. Add (ROW );
}
If (dtselectdata! = NULL & dtselectdata. Rows. Count> 0)
{
This. List. datasource = dtselectdata;
This. List. databind ();
}
Try
{
Datatable dtpage = getpage ();
String selectpage = page. request ["selectpage"];
For (INT I = 0; I <dtpage. Rows. Count; I ++)
{
Link link = new system. Web. UI. mobilecontrols. Link ();
If (I = convert. toint32 (selectpage ))
{
Link. Text = "[this page" + dtpage. Rows [I] [0]. tostring () + "]";
}
Else
{
Link. Text = "[" + dtpage. Rows [I] [0]. tostring () + "]";
}
Link. navigateurl = dtpage. Rows [I] [1]. tostring ();
Link. ID = I. tostring ();
Link. breakafter = false;
This. Panel. Controls. Add (Link );
}
}
Catch (exception exc)
{
This. lblmessage. Text = exc. message;
This. lblmessage. Visible = true;
}
}
Else
{
This. lblmessage. Text = "no record! ";
This. lblmessage. Visible = true;
}
}
Catch (exception exc)
{
This. lblmessage. Text = exc. message;
This. lblmessage. Visible = true;
}
}

Final Page effect:
 

Note: The maximum number of records displayed on each page can be customized in the globalsection attribute record. Page. Size node of Web. config. By default, 10 records are displayed on each page.

 

 

 

If you have any comments or suggestions, contact the author: Email: panqi7000 (a) 126.com. Replace (A) @.

Write by myxq

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.