国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
DataGrid終極分頁法:給分頁加上總記錄數(shù)、總頁數(shù)、當(dāng)前頁數(shù)
DataGrid終極分頁法:給分頁加上總記錄數(shù)、總頁數(shù)、當(dāng)前頁數(shù)
 如何給DataGrid加上總記錄數(shù)、總頁數(shù)、當(dāng)前頁數(shù)?如下圖所示:

    還是在DataGridPage.aspx.cs頁面里,找到DataGrid1_ItemCreated事件,在這個事件的最后,加上以下代碼:

Label la = new Label();
la.Text = "<table width=100%><tr><td align=left>總記錄數(shù):<b>"+ViewState["Row"].ToString()+" </b>";
la.Text += "總頁數(shù):<b>"+this.DataGrid1.PageCount+" </b>";
la.Text += "當(dāng)前頁:<font color=red><b>"+(this.DataGrid1.CurrentPageIndex+1).ToString()+" </b></font></td><td align=right>";
pager.Controls.AddAt(0,la);

Label lb = new Label();
lb.Text = "</td></tr></table>";
pager.Controls.Add(lb);

    然后在DataGridBind()的“DataView dv = ds.Tables[0].DefaultView;”后加上一句“ViewState["Row"] = dv.Count;”

    編譯后看看效果吧。下列是完整的頁面代碼:

DataGridPage.aspx:

<%@ Page language="c#" Codebehind="DataGridPage.aspx.cs" AutoEventWireup="false" Inherits="test.DataGridPage" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<HTML>

     <HEAD>

         <title>DataGridPage</title>

         <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">

         <meta name="CODE_LANGUAGE" Content="C#">

         <meta name="vs_defaultClientScript" content="JavaScript">

         <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

         <style type="text/css"> BODY { FONT-SIZE: 9pt; BACKGROUND-COLOR: #ffffff } A:visited { COLOR: #000000; TEXT-DECORATION: none } A:active { COLOR: #000000; TEXT-DECORATION: none } A:hover { LEFT: 1px; COLOR: #000000; POSITION: relative; TOP: 1px; TEXT-DECORATION: underline } A:link { COLOR: #000000; TEXT-DECORATION: none } TD { FONT-SIZE: 9pt; FONT-FAMILY: "宋體" } </style>

     </HEAD>

     <body>

         <form id="Form1" method="post" runat="server">

              <FONT face="宋體">

                   <asp:DataGrid id="DataGrid1" runat="server" AllowPaging="True">

                       <PagerStyle VerticalAlign="Middle" HorizontalAlign="Right" Mode="NumericPages"></PagerStyle>

                   </asp:DataGrid></FONT>

         </form>

     </body>

</HTML>

 

DataGridPage.aspx.cs:

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Data.OleDb;

 

namespace test

{

     /// <summary>

     /// DataGridPage 的摘要說明。

     /// </summary>

     public class DataGridPage : System.Web.UI.Page

     {

         protected System.Web.UI.WebControls.DataGrid DataGrid1;

         protected OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\\Program Files\\Microsoft Office\\OFFICE11\\SAMPLES\\Northwind.mdb");

    

         private void Page_Load(object sender, System.EventArgs e)

         {

              if (!this.IsPostBack)

              {

                   DataGridBind();

                  

              }

         }

 

         private void DataGridBind()

         {

              string strSql = "select * from 產(chǎn)品";

              DataSet ds = new DataSet();

              conn.Open();

              OleDbDataAdapter myAdapter =  new OleDbDataAdapter(strSql,conn);

              myAdapter.Fill(ds,"ds");

              conn.Close();

 

              DataView dv = ds.Tables[0].DefaultView;

              ViewState["Row"] = dv.Count;;

              this.DataGrid1.DataSource = dv;

              this.DataGrid1.DataBind();

         }

 

         #region Web 窗體設(shè)計器生成的代碼

         override protected void OnInit(EventArgs e)

         {

              //

              // CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計器所必需的。

              //

              InitializeComponent();

              base.OnInit(e);

         }

        

         /// <summary>

         /// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改

         /// 此方法的內(nèi)容。

         /// </summary>

         private void InitializeComponent()

         {   

              this.DataGrid1.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemCreated);

              this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);

              this.Load += new System.EventHandler(this.Page_Load);

 

         }

         #endregion

 

         private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)

         {

              this.DataGrid1.CurrentPageIndex = e.NewPageIndex;

              DataGridBind();

         }

 

         private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)

         {

              ListItemType elemType = e.Item.ItemType;

 

              if (elemType == ListItemType.Pager)

              {

                   TableCell pager = (TableCell)e.Item.Controls[0];

                   int up = 0;

                   int down = 0;

                   for (int i=0;i<pager.Controls.Count;i+=2)

                   {

                       Object o = pager.Controls[i];

                       if (o is LinkButton)

                       {

                            LinkButton h = (LinkButton) o;

                            if (h.Text!="...")

                            {

                                 h.ToolTip = "跳轉(zhuǎn)到第"+h.Text+"";

                            }

                            if (i==2)

                            {

                                 up = int.Parse(h.Text)-1;

                            }

                            if (i==pager.Controls.Count-3)

                            {

                                 down = int.Parse(h.Text)+1;

                            }

                       }

                       else

                       {

                            Label l = (Label) o;

 

                            if (i==2)

                            {

                                 up = int.Parse(l.Text)-1;

                            }

                            if (i==pager.Controls.Count-3)

                            {

                                 down = int.Parse(l.Text)+1;

                            }

 

                            l.Text = "["+l.Text+"]";

                            l.ForeColor = System.Drawing.Color.Red;

                       }

                   }

 

                   Object oo = pager.Controls[0];

                   if (oo is LinkButton)

                   {

                       LinkButton h = (LinkButton) oo;

                       if (h.Text=="...")

                       {

                            h.ToolTip = "跳轉(zhuǎn)到第"+up.ToString()+"";

                       }

                   }

 

                   Object ooo = pager.Controls[pager.Controls.Count-1];

                   if (ooo is LinkButton)

                   {

                       LinkButton h = (LinkButton) ooo;

                       if (h.Text=="...")

                       {

                            h.ToolTip = "跳轉(zhuǎn)到第"+down.ToString()+"";

                       }

                   }

 

                   Label la = new Label();

                   la.Text = "<table width=100%><tr><td align=left>總記錄數(shù):<b>"+ViewState["Row"].ToString()+" </b>";

                   la.Text += "總頁數(shù):<b>"+this.DataGrid1.PageCount+" </b>";

                   la.Text += "當(dāng)前頁:<font color=red><b>"+(this.DataGrid1.CurrentPageIndex+1).ToString()+" </b></font></td><td align=right>";

                   pager.Controls.AddAt(0,la);

 

                   Label lb = new Label();

                   lb.Text = "</td></tr></table>";

                   pager.Controls.Add(lb);

              }

         }

     }

}



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1579739

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
為datagrid的自帶分頁添加首頁、尾頁及狀態(tài)功能
ASP.NET 數(shù)據(jù)列表控件的分頁總結(jié)(二):使用存儲過程分頁
AngularJs的UI組件ui
Flex實現(xiàn)分頁顯示功能(mx:DataGrid)
給jqGrid數(shù)據(jù)行添加修改和刪除操作鏈接(可以執(zhí)行)
php中如何分頁顯示查詢數(shù)據(jù)結(jié)果
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服