AspNetPager 搜索返回当前页

 

CommodityList.aspx:

page
 1  <div style="margin: 0 auto; text-align: center; width: 500px;">
2 <asp:DropDownList ID="DropDownList1" runat="server">
3 <asp:ListItem Selected="True" Value="0">产品名称</asp:ListItem>
4 </asp:DropDownList>
5 <font style="font-size: 18px; color: #0000FF">--</font>
6 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp;&nbsp;
7 <asp:Button ID="Button1" runat="server" Text="搜索商品" OnClick="btnSearch_Click" />
8
9 </div>
10 <asp:DataList ID="DataList1" runat="server" Width="100%" RepeatLayout="Flow"
11 DataKeyField="commId" OnItemDataBound="DataList1_ItemDataBound" OnItemCommand="DataList1_ItemCommand">
12 <ItemTemplate>
13 <table width="100%" border="0" cellpadding="0" cellspacing="0">
14 <tr>
15 <td align="left">
16 <b><span style="font-weight: bold; color: #cc0066">编号:</span><%#Eval("commNum")%></b>
17 </td>
18 <td align="center">
19 <div style="color: #cc0066; width: 100%">
20 <div style="float: left; margin-left: 30px;">
21 <b>
22 <%#Eval("commName")%></b></div>
23 <div style="float: right; margin-right: 30px;">
24 <asp:Button ID="btnInfo" runat="server" Text="产品信息" CommandName="info" CommandArgument='<%#Eval("commId")%>' />&nbsp;&nbsp;&nbsp;
25
26 </div>
27 </div>
28 </td>
29 </tr>
30 <tr>
31 <td style="width: 120px; text-align: center;">
32 <a id="imgmax" href='..\UploadFiles\Images\<%#Eval("commImageId") %>'>
33 <img border="0" src='..\UploadFiles\Images\<%#Eval("commImageId") %>' class="imgmin"
34 alt='<%#Eval("commNum")%>' width="100px" height="90px" /></a>
35 </td>
36 <td>
37 <table width="100%" style="height: 90px" cellspacing="0" border="0" cellpadding="0">
38 <tr>
39 <td width="38%" align="left">
40 <span style="font-weight: bold; color: #cc0066">&nbsp;&nbsp;&nbsp;&nbsp;工艺:</span>
41 <%#Eval("commCraft")%>
42 </td>
43 <td width="39%" align="left">
44 <span style="font-weight: bold; color: #cc0066">&nbsp;&nbsp;&nbsp;&nbsp;颜色:</span>
45 <%#Eval("commColor")%>
46 </td>
47 <td>
48 <span style="font-weight: bold; color: #cc0066">&nbsp;&nbsp;&nbsp;&nbsp;型号:</span><%# Eval("commModel")%>
49 </td>
50 </tr>
51 <tr>
52 <td align="left">
53 <span style="font-weight: bold; color: #cc0066">&nbsp;&nbsp;&nbsp;&nbsp;材质:</span>
54 <%#Eval("commMaterial")%>
55 </td>
56 <td align="left">
57 <span style="font-weight: bold; color: #cc0066">&nbsp;&nbsp;&nbsp;&nbsp;规格:</span>
58 <%#Eval("commSpec")%>
59 </td>
60 <td>
61 &nbsp;
62 </td>
63 </tr>
64 <tr>
65 <td colspan="3" align="center">
66 &nbsp;&nbsp; <span style="font-weight: bold; color: #cc0066">相关描述:</span>
67 <%# (Eval("commDescription").ToString())%>
68 </td>
69 </tr>
70 </table>
71 </td>
72 </tr>
73 </table>
74 </ItemTemplate>
75 </asp:DataList>
76 <webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width="100%" NumericButtonCount="6"
77 NumericButtonTextFormatString="[{0}]" CustomInfoHTML="第 <font color='red'><b>%CurrentPageIndex%</b></font> 页 共 %PageCount% 页 显示 %StartRecordIndex%-%EndRecordIndex% 条 总<font color='red'><b>%RecordCount%</b></font>条"
78 ShowCustomInfoSection="left" FirstPageText="首页" LastPageText="末页" NextPageText="下页"
79 PrevPageText="上页" Font-Names="Arial" AlwaysShow="true" ShowPageIndexBox="Always"
80 SubmitButtonText="跳转" SubmitButtonStyle="button" CenterCurrentPageButton="True"
81 OnPageChanging="AspNetPager1_PageChanging">
82 </webdiyer:AspNetPager>



CommodityList.aspx.cs

code
 1 public partial class Commodity : System.Web.UI.Page
2 {
3
4 CommodityManager cm = new CommodityManager(); //数据源
5 protected void Page_Load(object sender, EventArgs e)
6 {
7 this.AspNetPager1.PageSize = 20; //每页最大显示条数
8
9 if (!IsPostBack)
10 {
11 //页码
12 object obj = Request.QueryString["Page"];
13 if (obj != null)
14 {
15
16 this.AspNetPager1_PageChanging(this.AspNetPager1, new Wuqi.Webdiyer.PageChangingEventArgs(Convert.ToInt32(obj)));
17 }
18 else
19 {
20 Session["SQL"] = "";
21 BindDataList(1, this.AspNetPager1.PageSize, Session["SQL"].ToString());
22 }
23 }
24 }
25
26
27 //绑定datalist
28 private void BindDataList(int pageIndex, int pageSize, string value)
29 {
30
31
32 this.AspNetPager1.RecordCount = cm.GetCommodityCount(value);
33 List<Commodity> list = cm.GetCommodityListSQL(pageIndex, pageSize, value);
34 this.dlCommodityList.DataSource = list;
35 this.dlCommodityList.DataBind();
36
37 }
38
39 protected void dlCommodityList_ItemCommand(object source, DataListCommandEventArgs e)
40 {
41 if (e.CommandName == "info")
42 {
43 Response.Redirect("info.aspx?Page=" + this.AspNetPager1.CurrentPageIndex + "&RecordCount=" + this.AspNetPager1.RecordCount + "&commId=" + e.CommandArgument.ToString());
44 }
45 }
46
47 //搜索按钮事件
48 protected void btnSearch_Click(object sender, EventArgs e)
49 {
50
51 string value = txtValue.Text.Replace("", "");
52
53 int key = Convert.ToInt32(ddlKey.SelectedValue);
54
55 switch (key)
56 {
57 case 0:
58 hfValue.Value = " commName LIKE '%" + value + "%' ";
59 break;
60 ......
61 }
62
63 Session.Add("SQL", hfValue.Value);
64 AspNetPager1.CurrentPageIndex = 1;
65 BindDataList(1, this.AspNetPager1.PageSize, Session["SQL"].ToString());
66 }
67
68 protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
69 {
70 this.AspNetPager1.RecordCount = MIS.UTIL.MISUtil.GetQueryStringPage("RecordCount");
71 AspNetPager1.CurrentPageIndex = e.NewPageIndex;
72 BindDataList(e.NewPageIndex, this.AspNetPager1.PageSize, Session["SQL"].ToString());
73 }
74
75
76 }

 

然后在info.aspx页传回Page,RecordCount,UTIL.GetQueryStringPage是处理请求的参数

 Response.Redirect("CommodityList.aspx?Page=" + UTIL.GetQueryStringPage("Page") + "&RecordCount=" + UTIL.GetQueryStringPage("RecordCount"));


这样可以实现搜索时,保持原来页面
 

posted on 2011-11-02 14:21  555[]  阅读(661)  评论(0编辑  收藏  举报

导航