📄 search.aspx.cs
字号:
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;
using Hugo.BookShop;
namespace BookShop
{
/// <summary>
/// Summary description for Search.
/// </summary>
public class Search : System.Web.UI.Page
{
protected System.Web.UI.WebControls.ImageButton btnReset;
protected System.Web.UI.WebControls.Label lblInfo;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DropDownList drp;
protected System.Web.UI.WebControls.TextBox txtName;
protected System.Web.UI.WebControls.TextBox txtAuthor;
protected System.Web.UI.WebControls.TextBox txtTranslator;
protected System.Web.UI.WebControls.TextBox txtPublisher;
protected System.Web.UI.WebControls.ImageButton btnSearch;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
lblInfo.Text = "";
Hugo.BookType myBookType=new Hugo.BookType();
DataView dv = myBookType.GetBookType();
this.drp.DataSource = dv;
this.drp.DataTextField = "Name";
this.drp.DataValueField = "Id";
this.drp.DataBind();
drp.Items.Add("All Types");
drp.Items[drp.Items.Count-1].Value = "-1";
drp.SelectedIndex = drp.Items.Count-1;
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSearch.Click += new System.Web.UI.ImageClickEventHandler(this.btnSearch_Click);
this.btnReset.Click += new System.Web.UI.ImageClickEventHandler(this.btnReset_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string Name = this.txtName.Text;
string Author = this.txtAuthor.Text.Trim();
string Translator = this.txtTranslator.Text.Trim();
string Publisher = this.txtPublisher.Text.Trim();
string TypeId = this.drp.Items[this.drp.SelectedIndex].Value;
string str = "";
if(int.Parse(TypeId)>=0)
{
str += " And TypeId=" + TypeId;
}
if(Author.Length>0)
{
str += " And Author Like '%" + Author + "%'";
}
if(Name.Length>0)
{
str += " And Name Like '%" + Name + "%'";
}
if(Translator.Length>0)
{
str += " And Translator Like '%" + Translator + "%'";
}
if(Publisher.Length>0)
{
str += " And Publisher Like '%" + Publisher + "%'";
}
Response.Redirect("GoSearch.aspx?Condition=" + str);
}
private void btnReset_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
this.txtName.Text = "";
this.txtAuthor.Text ="";
this.txtTranslator.Text ="";
this.txtPublisher.Text = "";
this.drp.SelectedIndex = this.drp.Items.Count -1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -