zoukankan      html  css  js  c++  java
  • ADO.NET站内模糊搜索

    Site.Master


    --------------------------------------------------------------------------------

    <td style="background-image: url('/image/index_r4_c8.jpg')">
              <asp:TextBox ID="TextBox1" runat="server" BackColor="#FF99CC" Height="16px"
               Width="100%"></asp:TextBox>
    </td>
    <td colspan="2">
              <asp:ImageButton ID="ImageButton1" runat="server" Height="27px"
               ImageUrl="~/image/index_r4_c9.jpg" Width="91px"
               onclick="ImageButton1_Click" />
     </td>

    Site.Master.cs


    --------------------------------------------------------------------------------

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
            {
                Session["keystr"] = TextBox1.Text.Trim();
                Response.Redirect("Search.aspx");
            }

    Class1.cs


    --------------------------------------------------------------------------------

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data .OleDb ;
    using System.Data ;


    namespace Mane
    {
        public class Class1
        {
            public  OleDbConnection strcon(string path)
            {
                OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+path );
                return con;
            }

            public DataTable selectTable(string sqltext, OleDbConnection con)
            {
                DataTable dt = new DataTable();
                OleDbDataAdapter adp = new OleDbDataAdapter(sqltext, con);
                adp.Fill(dt);
                return dt;
            }

            public void selectcmd(string sqltext, OleDbConnection con)
            {
                OleDbCommand cmd = con.CreateCommand();
                cmd.CommandText = sqltext;
               try
               {
                    con.Open();
                    cmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    throw new SystemException(e.Message);
                }
                finally
                {
                    con.Close();
                }
               
            }
        }
    }

    Search.aspx


    --------------------------------------------------------------------------------

    <asp:Label ID="Label1" runat="server"></asp:Label>
        <br />
    <asp:ListView ID="ListView1" runat="server"
                        GroupItemCount="6" style="text-align: center"
                        >

            <LayoutTemplate >
            <table id="Table1" runat ="server" style ="width :98%; height :auto ">
            <tr runat ="server" id="groupPlaceholder" style ="width :50%; height :auto "></tr>
            </table>
            </LayoutTemplate>

            <GroupTemplate >
            <tr id="Tr1" runat ="server">
            <td runat ="server" id="itemPlaceholder"></td>
            </tr>
            </GroupTemplate>

            <ItemTemplate >
            <td id="Td1" runat ="server" >
            <table style="border: 1px ; height: 113px; 100%; text-align: center;">
            <tr>
                <td colspan="2" style=" 174px; vertical-align :middle ;text-align: center; ">
                    <img alt="截图" height="110" src="image/pic/<%#Eval("图片") %>" width="100" style="padding: 2px" /></td>
                    </tr>
                    <tr>
                 <td colspan="2"> <%# Intercept(Eval("名称").ToString ())%></td></tr>
                 <td><a href ="<%#Eval("主页地址")%>" style="border: 2px solid #FF00FF; background-color: #CCCCCC;">转到>></a></td>
                 <td><a href ="Proj_body.aspx?id=<%#Eval("货号")%>" style="border: 2px solid #FF00FF; background-color: #CCCCCC;">详情>></a></td> 
            </tr>
              </table>
           </td>
            </ItemTemplate>

                    </asp:ListView>
                    <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1"
                        PageSize="42">
                        <Fields>
                            <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
                                ShowNextPageButton="False" />
                            <asp:NumericPagerField ButtonType="Button" />
                            <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True"
                                ShowPreviousPageButton="False" />
                        </Fields>
                    </asp:DataPager>

    Search.aspx

    --------------------------------------------------------------------------------


    protected void Page_Load(object sender, EventArgs e)
            {
                string qstr = Session["keystr"].ToString();
                if (qstr != null && qstr != "")
                {
                    Label1.Text = "查询结果如下:";
                    //如果点击了分类链接并传递了字符串则查询
                    Class1 cs = new Class1();
                    OleDbConnection con = cs.strcon(@Server.MapPath("/App_Data/Proj.mdb"));
                    string sql = "SELECT * FROM Proj  WHERE 名称 like '%" + qstr + "%' ORDER BY 排名竞价 DESC";
                    DataTable dt = cs.selectTable(sql, con);
                    ListView1.DataSource = dt;
                    ListView1.DataBind();
                }
                else
                {
                    Label1.Text = "请输入关键字!";
                }
            }


    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/mane_yao/archive/2010/07/25/5763683.aspx

  • 相关阅读:
    keyset与entryset
    solr4.9r+ Eclipse 4.3+ tomcat 7.5 +winds7(二)
    如何解决This system is not registered with RHN.
    堆和栈的差别(转过无数次的文章)
    墨菲定律、二八法则、马太效应、手表定理、“不值得”定律、彼得原理、零和游戏、华盛顿合作规律、酒与污水定律、水桶定律、蘑菇管理原理、钱的问题、奥卡姆剃刀等13条是左右人生的金科玉律
    atitit.软件开发GUI 布局管理优缺点总结java swing wpf web html c++ qt php asp.net winform
    漫谈并发编程(二):java线程的创建与基本控制
    exosip
    PostgreSQL服务端监听设置及client连接方法
    APK反编译。
  • 原文地址:https://www.cnblogs.com/mane/p/1829936.html
Copyright © 2011-2022 走看看