分页3
来源:互联网 发布:阿里云os电视系统 编辑:程序博客网 时间:2024/04/29 01:54
笨鸟不懂得先飞
- 总访问量:11839 - 今日访问:64 - 积 分:22802 - 等 级:6 - 文章总数:50 - 评论总数:35 - 订阅人数: 0
DataGrid终极分页法(三):给分页的页码加上ToolTip 原创 smallfools 2006-04-14 09:18:53 查看评论 ToolTip就是把鼠标放在链接上所显示的文字,如下图所示,本章将说明怎么加上这个文字。
0 && image.height>0){if(image.width>=510){this.width=510;this.height=image.height*510/image.width;}}" border=0>
打开DataGridPage.aspx.cs文件,找到DataGrid1_ItemCreated事件,把里面内容改成:
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 = "跳转到第"+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;
{
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 = "跳转到第"+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;
}
{
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;
}
}
l.ForeColor = System.Drawing.Color.Red;
}
}
Object oo = pager.Controls[0];
if (oo is LinkButton)
{
LinkButton h = (LinkButton) oo;
if (h.Text=="...")
{
h.ToolTip = "跳转到第"+up.ToString()+"页";
}
}
if (oo is LinkButton)
{
LinkButton h = (LinkButton) oo;
if (h.Text=="...")
{
h.ToolTip = "跳转到第"+up.ToString()+"页";
}
}
Object ooo = pager.Controls[pager.Controls.Count-1];
if (ooo is LinkButton)
{
LinkButton h = (LinkButton) ooo;
if (h.Text=="...")
{
h.ToolTip = "跳转到第"+down.ToString()+"页";
}
}
}
if (ooo is LinkButton)
{
LinkButton h = (LinkButton) ooo;
if (h.Text=="...")
{
h.ToolTip = "跳转到第"+down.ToString()+"页";
}
}
}
编译生成看看效果吧。以下是完整的代码:
DataGridPage.aspx:
<%@ Page language="c#" Codebehind="DataGridPage.aspx.cs" AutoEventWireup="false" Inherits="test.DataGridPage" %>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>DataGridPage</title>
<metaname="GENERATOR"Content="Microsoft Visual Studio .NET 7.1">
<metaname="CODE_LANGUAGE"Content="C#">
<metaname="vs_defaultClientScript"content="JavaScript">
<metaname="vs_targetSchema"content="http://schemas.microsoft.com/intellisense/ie5">
<styletype="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;"宋体" } </style>
</HEAD>
<body>
<formid="Form1"method="post"runat="server">
<FONTface="宋体">
<asp:DataGridid="DataGrid1"runat="server"AllowPaging="True">
<PagerStyleVerticalAlign="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 产品";
DataSet ds = new DataSet();
conn.Open();
OleDbDataAdapter myAdapter = new OleDbDataAdapter(strSql,conn);
myAdapter.Fill(ds,"ds");
conn.Close();
DataView dv = ds.Tables[0].DefaultView;
this.DataGrid1.DataSource = dv;
this.DataGrid1.DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
///<summary>
///设计器支持所需的方法 - 不要使用代码编辑器修改
///此方法的内容。
///</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 = "跳转到第"+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 = "跳转到第"+up.ToString()+"页";
}
}
Object ooo = pager.Controls[pager.Controls.Count-1];
if (ooo is LinkButton)
{
LinkButton h = (LinkButton) ooo;
if (h.Text=="...")
{
h.ToolTip = "跳转到第"+down.ToString()+"页";
}
}
}
}
}
}
标签: asp.net
票数:0 我顶
【发起辩论】 [手机订阅] [收藏到我的网摘] [推荐] | [评论] | [投诉] | [打印] 本文章被推荐到了0个圈子
点击数: 195
评论数: 0
本文章引用通告地址(TrackBack Ping URL)为:
http://post.blog.hexun.com/smallfools/trackback.aspx?articleid=3146203
本文章尚未被引用。
下一篇: DataGrid终极分页法(四):给分页加上总记录数、总页数...
上一篇: DataGrid终极分页法(二):美化分页
博客链条秀 我的博客链 web控件---HyperLink&html控件--. 点击:0 vbdotnet JavaScript传值及.Net传值方式总结 点击:0 vbdotnet Ajax简单应用,检测用户名是否存在 点击:0 vbdotnet 服务器端控件事件引起的页面刷新(.NE. 点击:2 ai火星鼠 asp.net和Rss的结合 点击:1 zfy0422 更多... 食疗:男人肾不好 吃什么能有效补充? 和讯博客家园全力打造平民星工厂 1 << < 2006 - 11 > >> Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 个人门户 网摘首页 相册首页 博揽首页 投诉本页 和讯博客首页 博客简介 主人名: smallfools
[发送私信][加为好友] 我是小笨笨
笨得不会笨鸟先飞的小笨笨
本博客文章都是原创,欢迎转载,但是转载请注明出处
最热文章TOP10 - 如何上传文件(图片) - 回答一个朋友的问题:... - DataGrid终极... - 如何打开或关闭FSO... - 上传图片或文件到数据... - DataGrid终极... - 与用户自定义控件交互... - 上传到数据库里的图片... - DataGrid终极... - 在SQL Serve...
最新文章 - 在SQL Serve... - 用SQL Serve... - 文件的操作(十):查... - 文件的操作(九):另... - 文件的操作(八):移... - 文件的操作(七):考... - 文件的操作(六):判... - 文件的操作(五):追... - asp文件无法执行的... - 文件的操作(四):修...
最新评论 - Re: 回答一个朋友... - Re: DataGr... - Re: 用asp.n... - Re: DataGr... - Re: DataGr... - Re: asp.ne... - Re: 用SQL ... - Re: 第一天开博,... - Re: 用asp.n... - Re: 如何上传文件...
标签 | TAG图 - asp.net - 对系统的不成熟意见 - SQL - Server - asp - js - 生活 - 其它 更多>>
朋友圈 - IT评点 - web2.0生活
和讯部落 1.0 beta Powered by BLOG.HEXUN.COM
- 分页3
- 分页存储过程3
- 分页技术3
- Oracle分页3
- 分页技术(3)
- 3、分页 (row_number函数)
- jpa 分页功能3
- 朝花夕拾(3)分页
- SpringMVC分页技术3
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- MySQL新强大特性——事件
- 合并DataGrid单元格
- 如何获取datetimepicker控件的年份
- BEA:出色构建 高效整合——厦门地税税收征管系统实施案例
- JSF的第一课
- 分页3
- 网页排版: Table vs CSS 争论之我见
- 反病毒引擎设计之实时监控篇
- 无法在web服务器上启动调试,未将项目配置为进行调试_解决方案
- 分页4
- IBM: Customer Order Analysis and Tracking System:从遗留结构到随需应变
- As3.0与java 5语法对比
- 分页5
- 数据结构(严蔚敏)抽象数据类型Triplet的表示与实现(第一章)