zoukankan      html  css  js  c++  java
  • 站内查询--根据类型进行

      (前台代码) 

    <asp:Label ID="Label4" runat="server" Text="新闻类型搜索" Width="300px"
            BackColor="#00CCFF" BorderColor="#00CCFF" BorderStyle="Solid" Height="16px" ></asp:Label>
        <asp:DropDownList ID="ddtype" runat="server" Height="20px" Width="115px" CssClass="css" CausesValidation="true">
        <asp:ListItem >热点</asp:ListItem>
        <asp:ListItem >国际</asp:ListItem>
        <asp:ListItem >国内</asp:ListItem>
        <asp:ListItem >体育</asp:ListItem>
        <asp:ListItem >女性</asp:ListItem>
        <asp:ListItem >教育</asp:ListItem>
         <asp:ListItem >财经</asp:ListItem>
        <asp:ListItem >Java</asp:ListItem>
         <asp:ListItem >军事</asp:ListItem>
        <asp:ListItem >娱乐</asp:ListItem>
        </asp:DropDownList>
        <asp:Button ID="Button1" runat="server" Text="查找" Height="30px" Width="60px"
            onclick="Button1_Click" />

    (后台代码)

      public static int IntSearch;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                IntSearch = 0;
                int n = Convert.ToInt32(Request.QueryString["ID"]);
                this.ddtype.SelectedIndex = (n - 1);
                this.bind();

    }

     protected void bind()
        {
            SqlConnection conn = DB.createSql();
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from T_new ", conn);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataTable table = new DataTable();
            sda.Fill(table);
            GridView1.DataSource = table;
            GridView1.DataKeyNames = new string[] { Convert.ToString(table.Columns["ID"]) };
            GridView1.DataBind();
        }

     protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)  

        {  

        //    bind(e.NewPageIndex);   

       }

         protected void GridView1_SelectdIndexChanged(object sender, EventArgs e)    

      {

         }   

       protected void Button1_Click(object sender, EventArgs e)    

      {          IntSearch = 1;       

            this.searchbind();    

      }     

    protected void searchbind()     

    {         

    string strsql = "select * from T_new where Type='" + this.ddtype.SelectedValue.ToString() + "'";         

    strsql += "and((Contents like'%" + txtKey.Text + "%')";        

     strsql += "or(Title like'%" + txtKey.Text + "%'))";       

       SqlConnection conn = DB.createSql();      

        conn.Open();         

    SqlCommand cmd = new SqlCommand(strsql, conn);      

        SqlDataAdapter sda = new SqlDataAdapter(cmd);        

      DataTable table = new DataTable();     

         sda.Fill(table);         

    GridView1.DataSource = table;        

      GridView1.DataKeyNames = new string[] { Convert.ToString(table.Columns["ID"]) };       

       GridView1.DataBind();   

       }

    }

  • 相关阅读:
    Repeater控件分页例子
    利用Repeater控件显示主-从关系数据表 (NestedRepeater.aspx)
    Visual C#设计多功能关机程序(2)
    ASP.Net 数据绑定之选择合适的数据控件
    模板化数据绑定控件示例
    Visual C#设计多功能关机程序(1)
    利用Repeater控件显示主-从关系数据表 (NestedRepeater.aspx.cs)
    iBatis 调用 PostgreSQL 存储过程返回结果集
    SubVersion 安装为 Windows 服务 (Service)
    Eclipse 运行使用指定的 JVM m2eclipse 插件找不到 com.sun 的 defaulttools.jar 的解决方案
  • 原文地址:https://www.cnblogs.com/ai394495243/p/3201320.html
Copyright © 2011-2022 走看看