添加工具提示分页链接在asp.net中的GridView [英] Add Tooltip to paging link in asp.net GridView

查看:169
本文介绍了添加工具提示分页链接在asp.net中的GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有可能最终显示5K左右记录一个gridview。目前,我有它设置为使用分页所以一次显示200条记录。要增加可用性,我想提供一些反馈,让他们找到一个记录更易于终端用户。我希望有,用户可以把鼠标移动到寻呼机链接之一,工具提示会显示记录的页面上提供的范围内的一种方式。

I have a gridview that could end up displaying about 5K records. I currently have it setup to use paging so it displays 200 records at a time. To add usability I'd like to provide the end user with some feedback that will allow them to locate a record easier. I was hoping there was a way that the user could put the mouse over one of the pager links and a tooltip would display the range of records available on the page.

例如:

用户将鼠标移动到页面#1链接,工具提示读艾博特 - BUELLER
用户将鼠标移动到页面#14的链接和工具提示读 MARTIN - PELLIGRINO

The user puts the mouse over the Page #1 link and the tooltip reads ABOTT - BUELLER The user puts the mouse over the Page #14 link and the tooltip reads MARTIN - PELLIGRINO

我将如何在ASP.NET做到这一点?

How would I accomplish this in ASP.NET?

推荐答案

您可以做到以下几点。首先创建一个空的PagerTemplate:

You could do the following. First create an empty PagerTemplate:

<asp:GridView 
ID="GridView1" 
runat="server" 
AllowPaging="true" 
PagerSettings-Mode="Numeric" 
PageSize="2" ondatabound="GridView1_DataBound">
    <PagerTemplate />
</asp:GridView>

现在响应DataBound事件可以添加控件的页导航行。这code只是增加了页码为LinkBut​​tons。

Now in response to the DataBound event you can add controls to the pager row. This code just adds the page numbers as LinkButtons.

protected void GridView1_DataBound(object sender, EventArgs e)
{
    GridViewRow pagerRow = GridView1.BottomPagerRow;

    for (int i = 0; i < GridView1.PageCount; i++)
    {
        LinkButton lb = new LinkButton();
        lb.Text = i.ToString();
        lb.ToolTip = "...";
        lb.CommandName = "Page";
        lb.CommandArgument = i.ToString();

        pagerRow.Cells[0].Controls.Add(lb);
    }

}

您还需要处理PageIndexChanging事件。

You'll also need to handle the PageIndexChanging event.

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex + 1;
    GridView1.DataBind();
}

现在剩下的工作就是制定出的工具提示文本应该是什么。对于那些你需要的顶部和底部行的索引的每一页。在这个例子中,它们将是:

Now all that remains is to work out what the ToolTip text should be. For that you'll need the indices of the top and bottom rows for every page. In this example they would be:

int topIndex = i * GridView1.PageSize;
int bottomIndex = ((i + 1) * GridView1.PageSize) - 1;

这篇关于添加工具提示分页链接在asp.net中的GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆