Use purely asp + language-based column Management (2)

Source: Internet
Author: User

Http://www.asp888.net bean curd technology station

Yesterday we saw the first part of the topic management program using the features of asp.net. In today's second part
We will display the data we entered on the input interface yesterday. In this section, we have made a dedicated one for paging management.
Pagelet: Through this pagelet, we perform paging processing on the selected records and review how our previous articles use custom pagelet in asp +.
Through this program, we will learn some intermediate technologies in asp.net programming (in fact, more advanced technologies, we currently)
In the process of learning and application, it seems that it has not been used! No, no, it's not using tofu :)
Next, let's first take a look at the ascx file we made: also called the User-Defined component file.
C. ascx:
<% @ Import Namespace = "System. Data" %>
<% @ Import Namespace = "System. Data. SQL" %>
<% @ Import Namespace = "System. Drawing" %>
<Script runat = server language = "C #">
Public SQLDataReader sRead; // The bound data.
Public int intPageCount = 5; // The number of data to be displayed on each page. The default value is 10.
Public int intRecStart = 0; // This is the starting position of the current data. The default value is 0.
Public int intCurrentRow = 0; // the position of the current Row pointer
Public int intRecCount; // The total number of records queried currently

Public void DataBind (){
Int I;
For (I = 0; I <intRecStart; I ++ ){
SRead. Read ();
}
}
Public String GetVal (String strName ){
SRead. Read ();
Return sRead [strName]. ToString ();
}
Public bool MyRead (){
If (! SRead. Read ())
Return false;
If (intCurrentRow = intPageCount)
Return false;
IntCurrentRow ++;
Return true;
}
Public void PageBar (){
TableCell c;
TableRow r = new TableRow ();
C = new TableCell ();
Int ii = intRecCount;
// (ArrayList) sRead;
String strWrite;
If (intRecStart = 0 ){
StrWrite = "Homepage ";
}
Else
{
StrWrite = "<a href = c. aspx? Start = 0> homepage </a> <a href = c. aspx? Start = "+ (intRecStart-intPageCount). ToString () +"> previous page </a> ";
}
If (intRecStart + intPageCount)> ii ){
StrWrite = strWrite + "Homepage ";
}
Else {
StrWrite = strWrite + "<a href = c. aspx? Start = "+ (intRecStart + intPageCount). ToString () +"> next page </a> <a href = c. aspx? Start = "+ (intRecStart + intPageCount). ToString () +"> last page </a> ";
}
C. Controls. Add (new LiteralControl (strWrite ));
R. Cells. Add (c );

C = new TableCell (); // generate a new column
C. Controls. Add (new LiteralControl ("total records" + ii. ToString ()));
R. Cells. Add (c );

Table1.Rows. Add (r );
}
</Script>
<Asp: table id = "Table1" GridLines = "Both" HorizontalAlign = "Center" Font-Name = "Verdana" Font-Size = "8pt" width = 100% Runat = "server"/>
Then, we can use the statement:
<% @ Register TagPrefix = "asp888" TagName = "myPageTable" Src = "c. ascx" %>
You can add the c. ascx file to any aspx file, and we can define
The Get and Set operations of parameters are the same as the properties and methods of the <asp: TextBox> operation.
<Asp888: myPageTable id = "menuControl1" runat = server/>. This is the PreFix and TagName defined in <% Register>.
In this way, we use this program to simulate the DataBind operation of the DataGrid, and also implement automatic paging.
<% @ Import Namespace = "System. Data" %>
<% @ Import Namespace = "System. Data. SQL" %>
<% @ Register TagPrefix = "asp888" TagName = "myPageTable" Src = "c. ascx" %>
<Script runat = server language = "C #">
Protected void Page_Load (Object Src, EventArgs E ){
Int intRecStart = Request. QueryString ["start"]. ToInt16 ();
SQLDataReader dbRead;
SQLCommand dbComm;
String strSQL;
String strConn;
SQLConnection conn;
Hashtable Cfg = new Hashtable ();
Cfg = (Hashtable) Context. GetConfig ("appsettings ");
StrConn = Cfg ["Conn"]. ToString ();
Conn = new SQLConnection (strConn );
// Obtain the total number of records first
StrSQL = "select count (*) from lanmu ";
DbComm = new SQLCommand (strSQL, conn );
DbComm. ActiveConnection. Open ();
DbComm. Execute (out dbRead );
DbRead. Read ();
Int intRecCount = dbRead. GetInt32 (0 );
DbComm. ActiveConnection. Close ();
StrSQL = "select * from lanmu order by id desc ";
DbComm = new SQLCommand (strSQL, conn );
DbComm. ActiveConnection. Open ();
DbComm. Execute (out dbRead );
MenuControl1.sRead = dbRead;
MenuControl1.intRecStart = intRecStart;
MenuControl1.intRecCount = intRecCount;
MenuControl1.DataBind ();
MenuControl1.PageBar ();
WriteTable ();
}
Void WriteTable (){
TableCell c;
TableRow r;


R = new TableRow (); // generate a new row
C = new TableCell (); // generate a new column
C. Controls. Add (new LiteralControl ("no "));
R. Cells. Add (c );

C = new TableCell (); // generate a new column
C. Controls. Add (new LiteralControl ("article title "));
R. Cells. Add (c );

C = new TableCell (); // generate a new column
C. Controls. Add (new LiteralControl ("times of reading "));
R. Cells. Add (c );
TableTest. Rows. Add (r );
While (menuControl1.MyRead ()){
R = new TableRow (); // generate a new row

C = new TableCell (); // generate a new column
C. Controls. Add (new LiteralControl (menuControl1.sRead ["id"]. ToString ()));
R. Cells. Add (c );

// The topic title is represented by HyperLink.
HyperLink h = new HyperLink ();
H. Text = menuControl1.sRead ["title"]. ToString ();
H. NavigateUrl = "viewarticle. aspx? Id = "+ menuControl1.sRead [" id "]. ToString ();
C = new TableCell (); // generate a new column
C. Controls. Add (h );
R. Cells. Add (c );

C = new TableCell (); // generate a new column
C. Controls. Add (new LiteralControl (menuControl1.sRead ["viewnum"]. ToString ()));
R. Cells. Add (c );

TableTest. Rows. Add (r );
}
Return;
}
</Script>
<Html>
<Head>
</Head>

<Body>
<Asp888: myPageTable id = "menuControl1" runat = server/>
<Asp: table id = "tableTest" width = 100% GridLines = "Both" Runat = "server" HorizontalAlign = "Center" Font-Name = "Verdana" Font-Size = "8pt" CellSpacing = 0/>
</Body>
</Html>
Of course, due to the time relationship, the functions of my program are still relatively rough and simple. I believe you only need
You can certainly learn a lot of knowledge. Work hard, comrades!


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.