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();   

       }

    }

  • 相关阅读:
    成为一名全栈工程师
    【DocFX文档翻译】DocFX 入门 (Getting Started with DocFX)
    SharePoint 2013 项目部署
    dynamics crm跳转到手机版本的页面
    Azure中block和Page的比较 Azure: Did You Know? Block vs Page Blobs
    斐讯k1路由器刷Breed BootLoader(不死UBoot)教程
    DynamicsCRM中的自动保存
    Migrating an ASP.NET MVC application to ADFS authentication
    说一下最近一个月的面试体会吧
    Boss直聘快速导出简历为PDF的方法
  • 原文地址:https://www.cnblogs.com/ai394495243/p/3201320.html
Copyright © 2011-2022 走看看