SoFunction
Updated on 2025-04-04

Save source code and use program paging

Source code:
Copy the codeThe code is as follows:

namespace Alex
{
public class PageTools
{
/// <summary>
/// Table name
/// </summary>
private string tableName;
public string TableName
{
get { return tableName; }
set { tableName = value; }
}
/// <summary>
/// Returned column name
/// </summary>
private string returnColumns;
public string ReturnColumns
{
get { return returnColumns; }
set { returnColumns = value; }
}
/// <summary>
/// condition
/// </summary>
private string where;
public string Where
{
get { return where; }
set { where = value; }
}
/// <summary>
/// Sort columns
/// </summary>
private string orderColumnName;
public string OrderColumnName
{
get { return orderColumnName; }
set { orderColumnName = value; }
}
/// <summary>
/// Sort, true in descending order
/// </summary>
private Boolean orderDesc;
public Boolean OrderDesc
{
get { return orderDesc; }
set { orderDesc = value; }
}
/// <summary>
/// Primary key
/// </summary>
private string keyColumnName;
public string KeyColumnName
{
get { return keyColumnName; }
set { keyColumnName = value; }
}
/// <summary>
/// Page size
/// </summary>
private Int32 pageSize;
public Int32 PageSize
{
get { return pageSize; }
set { pageSize = value; }
}
/// <summary>
/// What page
/// </summary>
private Int32 pageIndex;
public Int32 PageIndex
{
get { return pageIndex; }
set { pageIndex = value; }
}
/// <summary>
/// SQL parameters
/// </summary>
private SqlParameter[] whereParams;
public SqlParameter[] WhereParams
{
get { return whereParams; }
set { whereParams = value; }
}
/// <param name="TableName"></param>
/// <param name="ReturnColumns"></param>
/// <param name="Where">condition</param>
/// <param name="OrderColumnName">Sorting column</param>
/// <param name="OrderDesc">Sort, true in descending order</param>
/// <param name="KeyColumnName">Primary key</param>
/// <param name="PageSize">Page Size</param>
/// <param name="PageIndex">Which page</param>
/// <param name="WhereParams">SQL parameters</param>
public PageTools(string tableName, string returnColumns, string where, string orderColumnName, Boolean orderDesc,
string keyColumnName, Int32 pageSize, Int32 pageIndex, params SqlParameter[] whereParams)
{
= tableName;
= returnColumns;
= where;
= orderColumnName;
= orderDesc;
= keyColumnName;
= pageSize;
= pageIndex;
= WhereParams;
}
public PageTools() { }
public DataTable RetrievePagerData()
{
if (pageIndex == 1)
{
return RetrieveTopData();
}
else
{
string sql = ("select top {0} {1} from {2} where {3} and {6} not in ( select top {7} {6} from {2} where {3} order by {4} {5} ) order by {4} {5}", pageSize, returnColumns, tableName, where, orderColumnName, orderDesc == true ? "desc" : , keyColumnName, pageSize * (pageIndex - 1));
return (sql, CheckNull(whereParams)).Tables[0];
}
}
/// <summary>
/// Get the number of data
/// </summary>
/// <param name="TableName"></param>
/// <param name="Where"></param>
/// <param name="WhereParams"></param>
/// <returns></returns>
public Int32 RetrieveDataCount()
{
string sql = ("select count(*) from {0} where {1}" , tableName, where);
Int32 result = (Int32)(sql, CheckNull(whereParams));
return result;
}
/// <summary>
/// Get the first page
/// </summary>
/// <param name="top"></param>
/// <param name="TableName"></param>
/// <param name="ReturnColumns"></param>
/// <param name="Where"></param>
/// <param name="OrderColumnName"></param>
/// <param name="OrderDesc"></param>
/// <param name="WhereParams"></param>
/// <returns></returns>
public DataTable RetrieveTopData()
{
string sql = ("select top {0} {1} from {2} where {3} order by {4} {5}", pageSize, returnColumns, tableName, where, orderColumnName, orderDesc == true ? "desc" : );
return (sql, whereParams).Tables[0];
}
/// <summary>
/// Remove empty parameters
/// </summary>
/// <param name="WhereParams"></param>
/// <returns></returns>
private SqlParameter[] CheckNull(SqlParameter[] paras)
{
if (paras == null)
{
return null;
}
List<SqlParameter> list = new List<SqlParameter>();
foreach (SqlParameter para in paras)
{
if (para != null) (para);
}
return ();
}
}
}

Page background:
Copy the codeThe code is as follows:

public partial class _Default :
{
protected void Page_Load(object sender, EventArgs e)
{
recordCount = ();
totalPages = (int)(((double)recordCount / (double)));
if (!IsPostBack)
{
BindData();
}
}
page = new ("Test", "*", "1=1", "USER_Account", false, "USER_Account", 10, 1, null);
int recordCount;
public int totalPages;

private void BindData()
{
int pageIndex = ;
if(totalPages>0)
{
if(pageIndex>totalPages-1)
{
pageIndex=totalPages-1;
}
}
else
{
pageIndex=0;
}
=pageIndex;
=pageIndex+1;
= ();
();
if (this. == 0)
{
= false;
= false;
if (totalPages == 1)
{
= false;
= false;
}
}
else if (this. == totalPages - 1)
{
= false;
= false;
}
= ();
= (pageIndex + 1).ToString();
= ();
}
public void NavigateToPage(object sender, CommandEventArgs e)
{
= true;
= true;
= true;
= true;
string pageinfo = ();
switch (pageinfo)
{
case "Prev":
if (this. > 0)
{
this. -= 1;
}
break;
case "Next":
if (this. < (totalPages - 1))
{
this. += 1;
}
break;
case "First":
this. = 0;
break;
case "Last":
this. = totalPages - 1;
break;
}
if (this. == 0)
{
= false;
= false;
if (totalPages == 1)
{
= false;
= false;
}
}
else if (this. == totalPages - 1)
{
= false;
= false;
}
BindData();
}
protected void gobtnClick(object sender, EventArgs e)
{
int goPageIndex = Convert.ToInt32(());
if (goPageIndex > 0)
{
if (goPageIndex >= totalPages)
{
this. = totalPages - 1;
}
else
{
this. = goPageIndex - 1;
}
}
else if(goPageIndex <=0)
{
this. = 0;
}
if (this. == 0)
{
= false;
= false;
= true;
= true;
if (totalPages == 1)
{
= false;
= false;
}
}
else if (this. == totalPages - 1)
{
= false;
= false;
= true;
= true;
}
else
{
= true;
= true;
= true;
= true;
}
BindData();
}

Page front desk:

Code
Copy the codeThe code is as follows:

<%@ Page Language="C#" Theme="msn_blue" AutoEventWireup="true" CodeFile="" Inherits="_Default" %>
<%@ Register Assembly="SmartGridView" Namespace="" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script type="text/javascript">
function validate() {
var gocount=("goCount").value;
if(gocount=="")
{
alert("Please fill in the page you want to navigate first");
return false;
}
var result;
if(isNaN(gocount))
{
alert("Please enter a legal number");
("goCount").value="";
return false;
}
if(parseInt(gocount)<=0|| parseInt(gocount)><%= %>)
{
alert("number overflow");
("goCount").value="";
return false;
}
return true;
}
</script>
<form runat="server">
<div>
<table cellspacing="0" cellpadding="0" width="98%" align="center" border="0">
<tr runat="server">
<td align="left">
○ Pages: <asp:Label ID="lblpage" runat="server" ></asp:Label>/
<asp:Label ID="lblpagesum" runat="server"></asp:Label>, total: <asp:Label
ID="lblrowscount" runat="server"></asp:Label>bar</td>
<td align="right">
<asp:LinkButton ID="btnFirst" runat="server" OnCommand="NavigateToPage"
CommandArgument="First" CommandName="Pager" Text="Home">[Home]</asp:LinkButton><asp:LinkButton
ID="btnPrev" runat="server" CommandArgument="Prev" OnCommand="NavigateToPage"
CommandName="Pager" Text="Previous Page">[Previous Page]</asp:LinkButton><asp:LinkButton ID="btnNext"
runat="server" CommandArgument="Next" OnCommand="NavigateToPage"
CommandName="Pager" Text="Next Page">[Next Page]</asp:LinkButton><asp:LinkButton ID="btnLast"
runat="server" CommandArgument="Last" OnCommand="NavigateToPage"
CommandName="Pager" Text="Last Page" >[Last Page]</asp:LinkButton>
<asp:TextBox ID=goCount runat="server" Width="50px"></asp:TextBox>
<asp:Button ID="gobtn" runat="server" Text="go" OnClientClick="return validate();" OnClick="gobtnClick" /></td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" width="98%" align="center" border="0">
<tr>
<td>
<uc1:SmartGridView ID="SmartGridView1" SkinID="blue" runat="server"
PagingStyle="Default"
CssClassMouseOver="grid_over" EnableViewState="False"
AutoGenerateColumns="False"
Width="100%" currentLanguage="">
<Columns>
<asp:TemplateField>
<headertemplate>
<asp:checkbox runat="server" />
</headertemplate>
<itemtemplate>
<asp:checkbox runat="server" __designer:wfd></asp:checkbox>
</itemtemplate>
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" width="5px" cssclass="tdcell" />
</asp:TemplateField>
<asp:BoundField DataField="USER_Account" HeaderText="User Account" SortExpression="USER_Account">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_DspName" HeaderText="Display Name" SortExpression="USER_DspName">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_DspEngName" HeaderText="English name" SortExpression="USER_DspEngName" >
<headerstyle cssclass="tdcell" />
<itemstyle cssclass="tdcell" horizontalalign="Center" />
</asp:BoundField>
<asp:BoundField DataField="USER_HRID" HeaderText="Employee Number" SortExpression="USER_HRID" >
<headerstyle cssclass="tdcell" />
<itemstyle cssclass="tdcell" horizontalalign="Center" />
</asp:BoundField>
<asp:BoundField DataField="USER_Email" HeaderText="Email Address" SortExpression="USER_Email">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_Title" HeaderText="Job Title" SortExpression="USER_Title">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_Tel" HeaderText="Tel" SortExpression="USER_Tel">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_Active" HeaderText="Is it valid" SortExpression="USER_Active">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_Major" HeaderText="Professional" SortExpression="USER_Major" >
<headerstyle cssclass="tdcell" horizontalalign="Center" />
<itemstyle cssclass="tdcell" horizontalalign="Center" />
</asp:BoundField>
</Columns>
<HeaderStyle CssClass="thHead" />
<FixRowCol TableHeight="" TableWidth="" />
<RowStyle CssClass="tdcell" />
</uc1:SmartGridView>
</td></tr>
</table>
</div>
</form>
</body>
</html>