📄 search.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Search : System.Web.UI.Page
{
private String strkey;
protected void Page_Load(object sender, EventArgs e)
{
if(Request.QueryString["strkey"]!="")
{
strkey = Request.QueryString["strkey"].ToString();
}
if(!Page.IsPostBack)
{
this.GetProductSearchDataBind();
}
}
private void GetProductSearchDataBind()
{
ProductDB pdb = new ProductDB();
if (pdb.GetSearchProductCountByKey(strkey) > 0)
{
SqlDataReader Sdr = pdb.GetSearchProductDataByKey(strkey);
this.DListSearch.DataSource = Sdr;
this.DListSearch.DataBind();
this.LabelMsg.Visible = false;
Sdr.Close();
}
else
{
this.DListSearch.Visible = false;
this.LabelMsg.Text = "没有查询到关键字所属的商品!";
}
}
public String GetProductDescription(String des)
{
if (des.Length > 255)
{
return des.Substring(0, 255) + "...";
}
else
{
return des;
}
}
protected void DListSearch_ItemCommand(object source, DataListCommandEventArgs e)
{
if (!User.Identity.IsAuthenticated)
{
Response.Redirect("~/login_Register.aspx");
}
else
{
Shopcart shopcart = new Shopcart();
shopcart.CustomerID = User.Identity.Name;
shopcart.Quantity = 1;
shopcart.ProductID = Int32.Parse(e.CommandArgument.ToString());
ShopcarDB Sdb = new ShopcarDB();
if (Sdb.GetShopcartItem(shopcart) > 0)
{
Sdb.UpdateShopCartFirst(shopcart, true);
}
else
{
Sdb.AddShopCart(shopcart);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -