這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)ASP.NET 中怎么利用DataGrid自定義分頁(yè),文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
創(chuàng)新互聯(lián)是一家專業(yè)從事成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)的品牌網(wǎng)絡(luò)公司。如今是成都地區(qū)具影響力的網(wǎng)站設(shè)計(jì)公司,作為專業(yè)的成都網(wǎng)站建設(shè)公司,創(chuàng)新互聯(lián)依托強(qiáng)大的技術(shù)實(shí)力、以及多年的網(wǎng)站運(yùn)營(yíng)經(jīng)驗(yàn),為您提供專業(yè)的成都網(wǎng)站建設(shè)、營(yíng)銷型網(wǎng)站建設(shè)及網(wǎng)站設(shè)計(jì)開發(fā)服務(wù)!
ASP.NET DataGrid自定義分頁(yè)代碼1
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class article : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int cpage = Convert.ToInt32(Request.QueryString["page"]); if(cpage==0) { this.hlFrontPage.NavigateUrl = Request.ServerVariables["SCRIPT_NAME"]; this.hlNextPage.NavigateUrl = Request.ServerVariables["SCRIPT_NAME"] + "?page=" + Convert.ToString(cpage + 2); } else { this.hlFrontPage.NavigateUrl = Request.ServerVariables["SCRIPT_NAME"] + "?page=" + Convert.ToString(cpage - 1); this.hlNextPage.NavigateUrl = Request.ServerVariables["SCRIPT_NAME"] + "?page=" + Convert.ToString(cpage + 1); } this.hlFirstPage.NavigateUrl = Request.ServerVariables["SCRIPT_NAME"]; dataBin(); //*************************************************** //PageCount的值必須在數(shù)據(jù)綁定之后才能得到,否則只能是0 //*************************************************** int lastPage =this.DataGrid1.PageCount;//lastPage是記錄總頁(yè)數(shù) this.hlLastPage.NavigateUrl = Request.ServerVariables["SCRIPT_NAME"] + "?page="+Convert.ToInt32(lastPage); if (cpage ==Convert.ToInt32(this.DataGrid1.PageCount)) { this.hlNextPage.NavigateUrl = Request.ServerVariables["SCRIPT_NAME"] + "?page=" + Convert.ToString(lastPage); this.hlFrontPage.NavigateUrl = Request.ServerVariables["SCRIPT_NAME"] + "?page=" + Convert.ToString(cpage - 1); } this.lbShowMess.Text= "當(dāng)前第"+Convert.ToInt32(this.DataGrid1.CurrentPageIndex+1)+"頁(yè)"; } public void dataBin() { DB mydb = new DB(); SqlConnection conn = mydb.createConn(); conn.Open(); SqlDataAdapter sdr = new SqlDataAdapter(); DataSet ds = new DataSet(); sdr.SelectCommand = new SqlCommand("select * from [User]", conn); sdr.Fill(ds, "users"); int page=Convert.ToInt32(Request.QueryString["page"]); if (page == 0) { page = 1; } this.DataGrid1.CurrentPageIndex =Convert.ToInt32(page-1); this.DataGrid1.DataSource = ds.Tables["users"]; this.DataGrid1.DataBind(); conn.Close(); } protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e) { } }
再將以下內(nèi)容拷貝到article.aspx中
ASP.NET DataGrid自定義分頁(yè)代碼2
< %@ Page Language="C#" AutoEventWireup="true" CodeFile="article.aspx.cs" Inherits="article" %> < !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>無標(biāo)題頁(yè)< /title> < mce:style type="text/css">< !-- @import url('css.css'); -->< /mce:style>< style type="text/css" mce_bogus="1"> @import url('css.css'); < /style> < /head> < body> < form id="form1" runat="server"> < div style="text-align: center" mce_style="text-align: center"> < asp:DataGrid ID="DataGrid1" runat="server" AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanged="DataGrid1_PageIndexChanged" Width="500px" ShowHeader="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None" CellPadding="4" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" GridLines="None"> < Columns> < asp:TemplateColumn> < ItemTemplate> < %# DataBinder.Eval(Container.DataItem,"id") %> < /ItemTemplate> < HeaderStyle Width="10px" /> < ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" /> < /asp:TemplateColumn> < asp:TemplateColumn> < ItemTemplate> < %# DataBinder.Eval(Container.DataItem,"Uid") %> < /ItemTemplate> < ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" /> < HeaderStyle Width="450px" /> < /asp:TemplateColumn> < asp:TemplateColumn> < ItemTemplate> < %# DataBinder.Eval(Container.DataItem,"title") %> < /ItemTemplate> < HeaderStyle Width="30px" /> < ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" /> < /asp:TemplateColumn> < asp:TemplateColumn> < ItemTemplate> < input id="Checkbox1" type="checkbox" value="< %# DataBinder.Eval(Container.DataItem,"id") %>" /> < /ItemTemplate> < HeaderStyle Width="10px" /> < ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" /> < /asp:TemplateColumn> < /Columns> < PagerStyle Visible="False" BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" /> < FooterStyle BackColor="#FFFFCC" ForeColor="#330099" /> < SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" /> < ItemStyle BackColor="White" ForeColor="#330099" /> < HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" /> < /asp:DataGrid> < br /> < asp:HyperLink ID="hlFirstPage" runat="server">首頁(yè)< /asp:HyperLink> < asp:HyperLink ID="hlFrontPage" runat="server">上一頁(yè)< /asp:HyperLink> < asp:HyperLink ID="hlNextPage" runat="server">下一頁(yè)< /asp:HyperLink> < asp:HyperLink ID="hlLastPage" runat="server">末頁(yè)< /asp:HyperLink> < asp:Label ID="lbShowMess" runat="server" Width="104px">< /asp:Label>< /div> < /form> < /body> < /html>
上述就是小編為大家分享的ASP.NET 中怎么利用DataGrid自定義分頁(yè)了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
文章標(biāo)題:ASP.NET中怎么利用DataGrid自定義分頁(yè)
網(wǎng)頁(yè)地址:http://www.rwnh.cn/article20/pcoejo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、、用戶體驗(yàn)、網(wǎng)站營(yíng)銷、品牌網(wǎng)站制作、微信公眾號(hào)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)