• asp.net 实现搜索站内搜索功能


    首先有index和search 两个页面 index页面中有textbox1和button1两个控件 双击button1控件添加代码:

    1 protected void Button1_Click(object sender, EventArgs e)
    2         {
    3             string Key = this.TextBox1.Text;
    4             Response.Redirect("search.aspx?Key=" + Key);
    5         }

    将textbox1中的值传给search页面,接着打开search页面,首先接受jindex页面传过来的值

    string Key = Request.QueryString["Key"].ToString();

    然后连接数据库,进行模糊查询。再将查询到的结果显示到listview中:

     1 protected void load()
     2         {
     3             string Key = Request.QueryString["Key"].ToString(); //接受A页面参数
     4             SqlConnection conn = new SqlConnection("Server=.;database=Flower;uid=sa;pwd=zhuwenfan");  //连接数据库
     5             conn.Open(); //打开数据库
     6             SqlDataAdapter sda = new SqlDataAdapter("select * from FLOWERS_INFORMAYION where I_NAME like '%" + Key + "%'", conn);  //模糊查找
     7             DataTable Data = new DataTable();  //声明一个DataTable变量叫Data 
     8             sda.Fill(Data);  //填充这个Data 
     9             conn.Close(); //关闭数据库
    10             this.ListView1.DataSource = Data;
    11             this.ListView1.DataBind();
    12         }

    这样就实现了简单的搜索功能。

  • 相关阅读:
    Spring系列-JDBC实例
    postman-记录cookies信息
    根据URL获取参数值得出json结果集,对外给一个接口让别人调用
    linux 软硬链接
    第一个shell程序
    Argparse简易教程
    SQLAlchemy 教程 —— 基础入门篇
    人机对战初体验—四子棋游戏
    python的Flask 介绍
    python的项目结构
  • 原文地址:https://www.cnblogs.com/lihuazou/p/3727107.html
Copyright © 2020-2023  润新知