婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > .net搜索查詢并實(shí)現(xiàn)分頁(yè)實(shí)例

.net搜索查詢并實(shí)現(xiàn)分頁(yè)實(shí)例

熱門標(biāo)簽:杭州智能電話機(jī)器人 百度地圖標(biāo)注點(diǎn)擊事件 內(nèi)蒙古智能電銷機(jī)器人哪家強(qiáng) 地圖標(biāo)注位置多的錢 怎樣在地圖標(biāo)注消火栓圖形 廈門四川外呼系統(tǒng) 泰州手機(jī)外呼系統(tǒng)軟件 濟(jì)源人工智能電話機(jī)器人價(jià)格 山東防封電銷卡辦理套餐

前臺(tái):

復(fù)制代碼 代碼如下:

%@ Page Language="C#" AutoEventWireup="true" CodeBehind="分頁(yè).aspx.cs" Inherits="分頁(yè)練習(xí).分頁(yè)" %>
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
html xmlns="http://www.w3.org/1999/xhtml">
head runat="server">
    title>/title>
/head>
body>
    form id="form1" runat="server">
    div>
    table>
        tr>td>
            asp:TextBox ID="txtKey" runat="server">/asp:TextBox>
            asp:ImageButton ID="btnQuery" runat="server" onclick="btnQuery_Click" ImageUrl="~/images/0.jpg" Width="20" Height="20" />
            asp:Label ID="Label1" runat="server" Text="">/asp:Label>
            /td>
        /tr>
        tr>td>div id="divResult" runat="server">/div>/td>/tr>
        tr>td>
            asp:LinkButton ID="btnFirst" runat="server" onclick="btnFirst_Click">第一頁(yè)/asp:LinkButton>
            asp:LinkButton ID="btnBefore" runat="server" onclick="btnBefore_Click">上一頁(yè)/asp:LinkButton>
            asp:LinkButton ID="btnNext" runat="server" onclick="btnNext_Click">下一頁(yè)/asp:LinkButton>
            asp:LinkButton ID="btnLast" runat="server" onclick="btnLast_Click">最后一頁(yè)/asp:LinkButton>
            /td>
        /tr>
    /table>
    /div>
    /form>
/body>
/html>

后臺(tái):

復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Text;
namespace 分頁(yè)練習(xí)
{
    public partial class 分頁(yè) : System.Web.UI.Page
    {
        int pagesize = 3;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //ViewState雖然是聲明在函數(shù)內(nèi)部,看似是局部變量,但是在類中的其他函數(shù)中也可以直接使用
                ViewState["pageindex"] = 1;
                LoadData();
                Count();
            }
        }
        //搜索查詢
        private void LoadData()
        {
            string strcon = "Data Source=PC-DLL;Initial Catalog=News;Persist Security Info=True;User Id=sa;Password=linlin";
            SqlConnection conn = new SqlConnection(strcon);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandText = "SELECT TOP(@pagesize) * FROM T_News WHERE(NewsTitle LIKE @newskey OR NewsContent LIKE @newskey) AND Id NOT IN(SELECT TOP ((@pageindex-1)*@pagesize) Id FROM T_News WHERE NewsTitle LIKE @newskey OR NewsContent LIKE @newskey ORDER BY Id )ORDER BY Id";
            cmd.Parameters.AddWithValue("@newskey", "%" + txtKey.Text + "%");
            cmd.Parameters.AddWithValue("@pagesize",pagesize);
            cmd.Parameters.AddWithValue("@pageindex", Convert.ToInt32(ViewState["pageindex"]));
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            StringBuilder sb1 = new StringBuilder();
            sb1.Append("table>");
            sb1.Append("tr>td>標(biāo)題/td>td>內(nèi)容/td>td>創(chuàng)建時(shí)間/td>/tr>");
            foreach (DataRow row in dt.Rows)
            {
                sb1.Append("tr>");
                sb1.Append("td>" + row["NewsTitle"].ToString() + "/td>");
                sb1.Append("td>" + row["NewsContent"].ToString() + "/td>");
                sb1.Append("td>" + row["CreateTime"].ToString() + "/td>");
                sb1.Append("/tr>");
            }
            sb1.Append("/table>");
            divResult.InnerHtml = sb1.ToString();
        }
        private void Count()
        {
            string strcon = "Data Source=PC-DLL;Initial Catalog=News;Persist Security Info=True;User Id=sa;Password=linlin";
            SqlConnection conn = new SqlConnection(strcon);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandText = "SELECT COUNT(*) FROM T_News WHERE NewsTitle LIKE @newskey OR NewsContent LIKE @newskey";
            cmd.Parameters.AddWithValue("@newskey", "%" + txtKey.Text + "%");
            conn.Open();
            int totalcount = Convert.ToInt32(cmd.ExecuteScalar());
            if (totalcount % pagesize == 0)
            {
                ViewState["pagelastindex"] = totalcount / pagesize;
            }
            else
            {
                ViewState["pagelastindex"] = totalcount / pagesize + 1;
            }
            cmd.Dispose();
            conn.Dispose();
        }
        //第一頁(yè)
        protected void btnFirst_Click(object sender, EventArgs e)
        {
            ViewState["pageindex"] = 1;
            LoadData();
        }
        //上一頁(yè)
        protected void btnBefore_Click(object sender, EventArgs e)
        {

            int pageindex = Convert.ToInt32(ViewState["pageindex"]);
            if (pageindex > 1)
            {  
                pageindex--;
                ViewState["pageindex"] = pageindex;
                LoadData();
            } 
        }
        //下一頁(yè)
        protected void btnNext_Click(object sender, EventArgs e)
        {
            int pageindex = Convert.ToInt32(ViewState["pageindex"]);
            if (pageindex Convert.ToInt32(ViewState["pagelastindex"]))
            {
                pageindex++;
                ViewState["pageindex"] = pageindex;
                LoadData();
            } 
        }
        //最后一頁(yè)
        protected void btnLast_Click(object sender, EventArgs e)
        {
            ViewState["pageindex"] = ViewState["pagelastindex"];
            LoadData();
        }
        protected void btnQuery_Click(object sender, ImageClickEventArgs e)
        {
            Count();
            LoadData();
        }
    }
}

您可能感興趣的文章:
  • ASP.NET MVC5 實(shí)現(xiàn)分頁(yè)查詢的示例代碼
  • asp.net中g(shù)ridview的查詢、分頁(yè)、編輯更新、刪除的實(shí)例代碼
  • MVC+EasyUI+三層新聞網(wǎng)站建立 分頁(yè)查詢數(shù)據(jù)功能(七)

標(biāo)簽:洛陽(yáng) 周口 朔州 朝陽(yáng) 百色 新鄉(xiāng) 喀什 臺(tái)州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《.net搜索查詢并實(shí)現(xiàn)分頁(yè)實(shí)例》,本文關(guān)鍵詞  .net,搜索,查詢,并,實(shí)現(xiàn),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《.net搜索查詢并實(shí)現(xiàn)分頁(yè)實(shí)例》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于.net搜索查詢并實(shí)現(xiàn)分頁(yè)實(shí)例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 隆子县| 永平县| 中西区| 灵川县| 大港区| 广灵县| 新昌县| 玉溪市| 蕉岭县| 泰安市| 东乡族自治县| 和龙市| 巴林左旗| 通许县| 武强县| 镇宁| 宜城市| 城步| 开鲁县| 门源| 吴忠市| 阜平县| 新龙县| 岚皋县| 湖口县| 申扎县| 阳泉市| 邳州市| 六枝特区| 游戏| 筠连县| 新竹县| 绥德县| 浦江县| 廉江市| 通海县| 鄱阳县| 南和县| 景洪市| 旌德县| 托里县|