Asp. NET common search paging program written with stored procedures

Source: Internet
Author: User
Tags rowcount sort table name tostring
Asp.net| program | stored Procedure | paging
The stored procedure is changed from the Bigeagle forum paging program. Please criticize! :)
Select.aspx
--------------------------------------------------------------------------------

<%@ Page language= "C #"%>
<%@ import namespace= "System.Data"%>
<%@ import namespace= "System.Data.SqlClient"%>
<script runat= "Server" >

protected void Page_Load (Object sender, EventArgs e)
{
int intpageno,intpagesize,intpagecount;
Intpagesize = 25;
if (request["CurrentPage"]==null)
{
Intpageno = 1;
}
Else
{
Intpageno = Int32.Parse (request["currentpage"));
}


SqlConnection mysqlconnection = new SqlConnection ("server= (local);D atabase=test;user id=sa;password=");
SqlCommand Mysqlcommand = new SqlCommand ("Up_gettopiclist", mysqlconnection);
Mysqlcommand.commandtype = CommandType.StoredProcedure;

SqlParameter Workparm;

Search for table fields, separated by ","
Workparm = MySqlCommand.Parameters.Add ("@a_TableList", SqlDbType.VarChar, 200);
mysqlcommand.parameters["@a_TableList"]. Value = "Offerid,type,offertime";

Search Table Name
Workparm = MySqlCommand.Parameters.Add ("@a_TableName", SqlDbType.VarChar, 30);
mysqlcommand.parameters["@a_TableName"]. Value = "Offer";

Search criteria, such as "select * from AA where a=1 and b=2 and c=3", the condition is "where a=1 and b=2 and C=3"
Workparm = MySqlCommand.Parameters.Add ("@a_SelectWhere", SqlDbType.VarChar, 500);
mysqlcommand.parameters["@a_SelectWhere"]. Value = "where type= ' idl '";

Table primary key field name, must be int type
Workparm = MySqlCommand.Parameters.Add ("@a_SelectOrderId", SqlDbType.VarChar, 50);
mysqlcommand.parameters["@a_SelectOrderId"]. Value = "OfferID";

Sort, you can sort with multiple fields but the primary key fields must be in the front
Workparm = MySqlCommand.Parameters.Add ("@a_SelectOrder", SqlDbType.VarChar, 50);
mysqlcommand.parameters["@a_SelectOrder"]. Value = "ORDER by OfferID Desc";

Page number
Workparm = MySqlCommand.Parameters.Add ("@a_intPageNo", SqlDbType.Int);
mysqlcommand.parameters["@a_intPageNo"]. Value = Intpageno;

Display number per page
Workparm = MySqlCommand.Parameters.Add ("@a_intPageSize", SqlDbType.Int);
mysqlcommand.parameters["@a_intPageSize"]. Value = intpagesize;

Total number of records (stored procedure output parameters)
Workparm = MySqlCommand.Parameters.Add ("@RecordCount", SqlDbType.Int);
Workparm.direction = ParameterDirection.Output;

Number of current page records (stored procedure return value)
Workparm = MYSQLCOMMAND.PARAMETERS.ADD ("RowCount", SqlDbType.Int);
Workparm.direction = ParameterDirection.ReturnValue;

Mysqlconnection.open ();
Repeater.datasource = Mysqlcommand.executereader ();

Repeater.databind ();

Mysqlconnection.close ();

Int32 RecordCount = (Int32) mysqlcommand.parameters["@RecordCount"]. Value;
Int32 rowcount = (Int32) mysqlcommand.parameters["rowcount"]. Value;

Labelrecord.text = Recordcount.tostring ();
Labelrow.text = Intpageno.tostring ();
Intpagecount = recordcount/intpagesize;
if ((recordcount%intpagesize) >0)
Intpagecount + 1;
Labelpage.text = Intpagecount.tostring ();

if (intpageno>1)
{
Hlfistpage.navigateurl = "Select.aspx?" Currentpage=1 ";
Hlprevpage.navigateurl = String.Concat ("Select.aspx?") Currentpage= "," ", intPageNo-1);
}
Else
{
Hlfistpage.navigateurl = "";
Hlprevpage.navigateurl = "";
hlfistpage.enabled = false;
hlprevpage.enabled = false;
}

if (Intpageno<intpagecount)
{
Hlnextpage.navigateurl = String.Concat ("Select.aspx?") Currentpage= "," ", intpageno+1);
Hlendpage.navigateurl = String.Concat ("Select.aspx?") Currentpage= "," ", Intpagecount);
}
Else
{
Hlnextpage.navigateurl = "";
Hlendpage.navigateurl = "";
Hlnextpage.enabled=false;
Hlendpage.enabled=false;
}

}

</script>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<link href= "/style.css" rel= "stylesheet"/>
<style type= "Text/css" >
. High {font-family: "Song body"; font-size:9pt; line-height:140%}
. mid {font-size:9pt; line-height:12pt}
. small {font-size:9pt; Line-height:normal}
. Tp10_5 {
font-size:14px;
line-height:140%;
}
</style>
<style type= "Text/css" >a:link {
COLOR: #cc6666
}
</style>
<body>
<form runat= "Server" >
<span class= "High" > <font color= "#CC0000" ><asp:label id= "Labelrow" runat= "Server"/></font> Page | Total <asp:label id= "labelpage" runat= "Server"/> Page
| <asp:label id= "Labelrecord" runat= "server"/> Message |
<asp:hyperlink id= "Hlfistpage" text= "Home" runat= "Server"/>
| <asp:hyperlink id= "Hlprevpage" text= "prev" runat= "Server"/>
| <asp:hyperlink id= "Hlnextpage" text= "next page" runat= "Server"/>
| <asp:hyperlink id= "Hlendpage" text= "Last" runat= "Server"/></span><br>

<asp:repeater id=repeater runat= "Server" >

<HeaderTemplate>

<table width= "583" border= "0" cellspacing= "0" cellpadding= "0" >
<tr>
&LT;TD bgcolor= "#000000" ><table width= "100%" border= "0" cellpadding= "4" cellspacing= "1" class= "Tp10_5" >
<tr bgcolor= "#999999" >
&LT;TD align= "center" > <strong><font color= "#FFFFFF" > Order number </font></strong></td>
&LT;TD align= "center" > <strong><font color= "#FFFFFF" > Service project </font></strong></td>
&LT;TD align= "center" > <strong><font color= "#FFFFFF" > Reservation date </font></strong></td>
&LT;TD align= "center" > <strong><font color= "#FFFFFF" > Operations Personnel </font></strong></td>
&LT;TD align= "center" > <strong><font color= "#FFFFFF" > Allocation status </font></strong></td>
<td> <div align= "center" ></div></td>
</tr>
</HeaderTemplate>

<ItemTemplate>

&LT;TR align= "center" bgcolor= "#FFFFFF" class= "small",
@SPintEndID = @intEndID, @SPintBeginID = @intBeginID

return (@ @rowcount)
--select @ @rowcount
Go



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.