searchproducts.aspx.cs
来自「手机网店源码」· CS 代码 · 共 229 行
CS
229 行
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace MobileOnlineShop
{
/// <summary>
/// searchProducts 的摘要说明。
/// </summary>
public class searchProducts : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label message;
protected System.Web.UI.WebControls.DataList MyList;
//专用明全局变量
// private int pageSize,recorderCount,currentPage,pageCount;
// //类型ID
// private int categoryId;
//
private void Page_Load(object sender, System.EventArgs e)
{
//每页记录数
// pageSize = 12;
// //品牌ID
// categoryId = Convert.ToInt32(Request.Params["CategoryID"]);
if(!Page.IsPostBack)
{
//根据手机型号搜索
if(Request.QueryString["searchModel"]!=null)
{
if(Request.QueryString["searchModel"].ToString() != "请输入手机型号")
{
MyList.DataSource = DAL.ProductDB.SearchProductByModel(Request.Params["searchModel"].ToString());
MyList.DataBind();
}
display();
return;
}
//根据手机品牌搜索
if(Request.QueryString["proName"].ToString() != "请选择手机品牌" && Request.QueryString["Index"].ToString()=="0")
{
MyList.DataSource = DAL.ProductDB.SearchProductByCategoryName(Request.Params["proName"]);
MyList.DataBind();
display();
return;
}
//根据手机价格搜索
if(Request.QueryString["Index"] != "0" && Request.QueryString["proName"].ToString() == "请选择手机品牌")
{
int seleIndex ;
try
{
seleIndex = Convert.ToInt32(Request.QueryString["Index"]);
}
catch
{
seleIndex = 0;
}
switch(seleIndex)
{
case 0:
break;
case 1:
MyList.DataSource = DAL.ProductDB.SearchProductByPrice(0,1000);
MyList.DataBind();
break;
case 2:
MyList.DataSource = DAL.ProductDB.SearchProductByPrice(1000,3000);
MyList.DataBind();
break;
case 3:
MyList.DataSource = DAL.ProductDB.SearchProductByPrice(3000,-1);
MyList.DataBind();
break;
}
display();
return;
}
//按手机价格和品牌搜索
if((Request.QueryString["proName"] != "请选择手机品牌")&&(Request.QueryString["Index"] != "0"))
{
string name ;
int seleIndex ;
try
{
seleIndex = Convert.ToInt32(Request.QueryString["Index"]);
name = Request.QueryString["proName"];
}
catch
{
seleIndex = 0;
name = null;
}
switch(seleIndex)
{
case 0:
break;
case 1:
MyList.DataSource = DAL.ProductDB.SearchProductByPriceName(0,1000,name);
MyList.DataBind();
break;
case 2:
MyList.DataSource = DAL.ProductDB.SearchProductByPriceName(1000,3000,name);
MyList.DataBind();
break;
case 3:
MyList.DataSource = DAL.ProductDB.SearchProductByPriceName(3000,-1,name);
MyList.DataBind();
break;
}
display();
}
// //调用数据访问层方法,计算记录条数
// recorderCount = DAL.ProductDB.RecorderCalculate(categoryId);
//
// //页数
// if((float)recorderCount/pageSize == recorderCount/pageSize)
// pageCount = recorderCount/pageSize;
// else
// pageCount = recorderCount/pageSize+1;
// this.lblPageCount.Text = pageCount.ToString();
// ViewState["PageCount"] = pageCount;
//
// currentPage = 1;
// ViewState["PageIndex"] = currentPage;
// BindList();
}
}
private void display()
{
if (MyList.Items.Count == 0)
{
MyList.Visible = false;
message.Text = "无搜索结果。";
}
}
// public void BindList()
// {
// this.m_lkbtnPrePage.Enabled = true;
// this.m_lkbtnNextPage.Enabled = true;
// pageCount = (int)ViewState["PageCount"];
//
// //清空m_ddlPageIndex
// this.m_ddlPageIndex.Items.Clear();
//
// for(int i=1;i<=pageCount;i++)
// this.m_ddlPageIndex.Items.Add(i.ToString());
// // 调用数据访问层方法,将返回结果与DataList绑定,并分页
// MyList.DataSource = DAL.ProductDB.GetProducts(categoryId,currentPage,pageSize);
// MyList.DataBind();
//
// if (currentPage == 1)
// {
// this.m_lkbtnPrePage.Enabled = false;
// }
// if (currentPage == pageCount)
// {
// this.m_lkbtnNextPage.Enabled = false;
// }
// // ViewState["PageIndex"] = currentPage;
//
// this.m_ddlPageIndex.SelectedIndex = currentPage-1;
// }
// private void m_ddlPageIndex_SelectedIndexChanged(object sender, System.EventArgs e)
// {
// currentPage = Int32.Parse(this.m_ddlPageIndex.SelectedValue);
// BindList();
// }
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
// private void m_lkbtnPrePage_Click(object sender, System.EventArgs e)
// {
// currentPage = (int)ViewState["PageIndex"];
// if ( currentPage >1)
// {
// currentPage--;
// ViewState["PageIndex"] = currentPage;
// }
// BindList();
// }
//
// private void m_lkbtnNextPage_Click(object sender, System.EventArgs e)
// {
// currentPage = (int)ViewState["PageIndex"];
// pageCount = (int)ViewState["PageCount"];
// if ( currentPage < pageCount)
// {
// currentPage++;
// ViewState["PageIndex"] = currentPage;
// }
// BindList();
// }
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?