📄 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 System.Data.SqlClient;
using System.Configuration;
using System.Security.Principal;
namespace WebNews
{
/// <summary>
/// search 的摘要说明。
/// </summary>
public class search : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlForm myForm;
protected System.Web.UI.WebControls.DataGrid MyDataGrid;
//protected HenryFan.WebControls.DisPage DisPage1;
protected System.Web.UI.WebControls.Label myLabel;
protected System.Web.UI.WebControls.TextBox keyword;
protected System.Web.UI.WebControls.ImageButton ImageButton1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DropDownList search1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
private void searchTitle() //搜索标题
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn = new SqlConnection(con);//连接字符串
conn.Open();
SqlDataAdapter myCommand = new SqlDataAdapter(); //创建SqlDataAdapter 类
myCommand.SelectCommand=new SqlCommand("sp_searchCkArticleByTitle",conn);
myCommand.SelectCommand.CommandType=CommandType.StoredProcedure ;
SqlParameter title=myCommand.SelectCommand.Parameters.Add("@title",SqlDbType.NVarChar ,500);
title.Value=Request["keyword"] ;
DataSet ds=new DataSet(); //建立并填充数据集
myCommand.Fill(ds,"Articl");
MyDataGrid.DataSource=ds;
MyDataGrid.DataBind();
conn.Close();
}
catch(SqlException e)
{
Response.Write("Exception in Main: " + e.Message); //出错处理
}
}
private void searchContent() //搜索内容
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn = new SqlConnection(con);//连接字符串
conn.Open();
SqlDataAdapter myCommand = new SqlDataAdapter(); //创建SqlDataAdapter 类
myCommand.SelectCommand=new SqlCommand("sp_searchCkArticleByContent",conn);
myCommand.SelectCommand.CommandType=CommandType.StoredProcedure ;
SqlParameter content=myCommand.SelectCommand.Parameters.Add("@content",SqlDbType.NText );
content.Value=Request["keyword"].Trim() ;
DataSet ds=new DataSet(); //建立并填充数据集
myCommand.Fill(ds,"Article");
MyDataGrid.DataSource=ds;
MyDataGrid.DataBind();
conn.Close();
}
catch(SqlException e)
{
Response.Write("Exception in Main: " + e.Message); //出错处理
}
}
public void ListClass(string de) //显示分类
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn = new SqlConnection(con);//连接字符串
conn.Open();
SqlCommand cmd=new SqlCommand("sp_selFclassAll",conn);
cmd.CommandType=CommandType.StoredProcedure;
SqlDataReader rd;
rd=cmd.ExecuteReader();
while (rd.Read())
{
Response.Write(de+"<a href=list.aspx?classname="+rd.GetString(1)+">"+rd.GetString(1)+"</a>");
}
rd.Close();
conn.Close();
}
catch(SqlException e)
{
Response.Write("Exception in Main: " + e.Message); //出错处理
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(Page.IsValid)
{
if(search1.SelectedIndex==0)
{
searchTitle();
}
else
{
searchContent();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -