当前位置:网站首页>asp. Net to search products and realize paging function
asp. Net to search products and realize paging function
2022-06-28 07:42:00 【No. 1006 Xiaobai】
The effect is as follows :
<form id="form1" runat="server">
<div class="row custom-content-search">
<div class="col-sm-2 col-md-2"></div>
<div class="col-sm-10 col-md-10">
<div class="input-group search">
<asp:TextBox ID="TextBox1" CssClass="form-control" runat="server" Width="685px" Height="35px"></asp:TextBox>
<asp:Button ID="Button1" CssClass="input-group-addon" runat="server" Text=" Search for " Height="35px" Width="50px" OnClick="Button1_Click" />
</div>
</div>
<div class="col-sm-2 col-md-2"></div>
</div>
<div class="row" style="margin-top:20px;">
<div class="col-sm-1 col-md-1"></div>
<div class="col-sm-2 col-md-2" >
<table cellpadding="0" cellspacing="0" class="auto-style3" >
<%
if (drs != null)
{
int i= 0;
foreach (System.Data.DataRow dr in drs)
{
i++;
if(i%5==1)
{
%>
<tr>
<%
}
%>
<td>
<a href="../GoodsDetials.aspx?id=<%=dr["good_id"]%>" onclick="SetID(<%=dr["good_id"] %>)"><%-- <asp:Image ID="img" runat="server" Width="195px" Height="195px" ImageUrl="~/images/new/1.jpg"/>--%>
<img Width="195px" Height="195px" alt="" src="<%=dr["good_path"].ToString().Replace("~","..") %>" />
</a>
<span style=" color:#3f90ca; font-size:18px;"> <%=dr["good_name"] %> </span>
</td>
<td><span style="margin-right:20px;"></span></td>
<%
if(i%5==0 || i==drs.Count)
{
%>
</tr><tr> <td> </td></tr>
<%
}
}
}
%>
</table>
</div>
</div>
<div class="row">
<div class="col-sm-4 col-md-4"></div>
<div class="col-sm-3 col-md-3" style="margin-top:15px; margin-bottom:15px; background-color:#cbe6fa; margin-left:50px; ">
common <asp:Label ID="TotalPageIndex" runat="server" Text="1"></asp:Label> page
Current <asp:Label ID="CurPageIndex" runat="server" Text="1"></asp:Label> page
<asp:LinkButton ID="UpPage" runat="server" OnClick="UpPage_Click"> The previous page </asp:LinkButton>
<asp:LinkButton ID="DownPage" runat="server" OnClick="DownPage_Click"> The next page </asp:LinkButton>
</div>
<div class="col-sm-5 col-md-5"></div>
</div>
</form>
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ShowPage_search : System.Web.UI.Page
{
Operation op = new Operation();
protected DataRowCollection drs = null; // Bind global variables of page data
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
DataBind(1);// The binding page data is loaded for the first time
}
private void DataBind(int PageIndex)
{
int PageSize = 10;// Define the total number of data per page
// Query data
string search = TextBox1.Text.ToString();
DataSet ds = op.SelectInfo22(search, PageIndex, PageSize);
if (ds != null && ds.Tables.Count > 0)
{
int Count = 0;
int.TryParse(ds.Tables[0].Rows[0][0].ToString(), out Count);// Get the total number of data pieces
drs = ds.Tables[1].Rows;
// Calculate paging data
int GetTotalPageIndex = (Count / PageSize) + ((Count % PageSize) > 0 ? 1 : 0);
this.TotalPageIndex.Text = GetTotalPageIndex.ToString();
this.CurPageIndex.Text = PageIndex.ToString();
if (PageIndex == 1 && PageIndex == GetTotalPageIndex)
{
SetPageState(0);// If the current total number of pages is 1 The style called when the page is opened
}
else if (PageIndex == 1)
{
SetPageState(1);// If the current style is the first page
}
else if (PageIndex == GetTotalPageIndex)
{
SetPageState(2);// If the current style is the last page
}
else
{
SetPageState(3);// The style called if the current page number is other than the first and last pages
}
}
}
/// <summary>
/// Processing method on the previous page
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void UpPage_Click(object sender, EventArgs e)
{
// Take out the current page number
int CurIndex = Convert.ToInt32(this.CurPageIndex.Text);
CurIndex--;// Subtract the current page number 1
DataBind(CurIndex);// Data binding
}
/// <summary>
/// Processing method on the next page
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DownPage_Click(object sender, EventArgs e)
{
// Take out the current page number
int CurIndex = Convert.ToInt32(this.CurPageIndex.Text);
CurIndex++;// Add... To the current page number 1
DataBind(CurIndex);// Data binding
}
/// <summary>
/// Set paging style
/// </summary>
/// <param name="SetIndex"></param>
public void SetPageState(int SetIndex)
{
// Set different styles according to different page numbers
if (SetIndex == 0)
{
this.UpPage.Enabled = false;
this.DownPage.Enabled = false;
this.UpPage.Style["color"] = "#808080";
this.DownPage.Style["color"] = "#808080";
}
else if (SetIndex == 1)
{
this.UpPage.Enabled = false;
this.DownPage.Enabled = true;
this.UpPage.Style["color"] = "#808080";
this.DownPage.Style["color"] = "#23527c";
}
else if (SetIndex == 2)
{
this.UpPage.Enabled = true;
this.DownPage.Enabled = false;
this.UpPage.Style["color"] = "#23527c";
this.DownPage.Style["color"] = "#808080";
}
else
{
this.UpPage.Enabled = true;
this.DownPage.Enabled = true;
this.UpPage.Style["color"] = "#23527c";
this.DownPage.Style["color"] = "#23527c";
}
}
}
/// <summary>
/// Query product information by page
/// </summary>
/// <param name="PageIndex"> Current page index sequence number </param>
/// <param name="PageSize"> Each page shows the number of records </param>
/// Query the first column of the entire table count(1) Query current page
/// <returns> Return query results DataSet Data sets </returns>
public DataSet SelectInfo22(string search, int PageIndex, int PageSize)
{
int StartIndex = ((PageIndex - 1) * PageSize) + 1;
int EndIndex = PageIndex * PageSize;
SqlParameter[] parms = {
data.MakeInParam("@info", SqlDbType.VarChar, 30, "%"+search+"%")
};
return data.RunProcReturn("select count(1) from good_info where good_name like @info ;" +
"select * from(SELECT good_id, good_name, good_path, Row_Number() over(ORDER BY good_id DESC) as rowIndex " +
"FROM good_info where good_name like @info) as Tab " +
"where rowIndex between " + StartIndex + " and " + EndIndex, parms, "good_info");
}
边栏推荐
- HJ删除字符串中出现次数最少的字符
- 8 张图 | 剖析 Eureka 的首次同步注册表
- Is it reliable to register and open an account for stock speculation? Is it safe?
- 异或的应用。(提取出数字中最右侧的1,面试中经常用的到)
- HJ成绩排序
- 腾讯下半年继续裁员,所有事业群至少缩减 10%,对此你怎么看?关注者
- ABAP skill tree
- R language Kolmogorov Smirnov tests whether the two samples follow the same distribution.
- Unity-UI-shadow组件
- QT -- communication protocol
猜你喜欢
随机推荐
Path alias specified in vite2.9
Leetcode learning records
linux下修改mysql用户名root
Construction and exploration of vivo database and storage platform
Is it reliable to open a new bond registration account? Is it safe?
代码提交规范
Design of DSP image data stream
Kubelet garbage collection (exiting containers and unused images) source code analysis
Redis implements distributed locks
Sword finger offer|: linked list (simple)
Code submission specification
Kubernetes cluster command line tool kubectl
pip 更新到最新的版本
Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
HJ character count
股票炒股注册开户靠谱吗?安全吗?
Section 9: dual core startup of zynq
Section 8: DMA of zynq
HJ string sort
es6箭头函数中return的用法






![[ thanos源码分析系列 ]thanos query组件源码简析](/img/e4/2a87ef0d5cee0cc1c1e1b91b6fd4af.png)


