首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >寻呼GridView

寻呼GridView
EN

Stack Overflow用户
提问于 2011-02-01 20:53:18
回答 2查看 2K关注 0票数 3

我有一个简单的问题:

代码语言:javascript
复制
Dim info As New SailMembersDataContext
Dim query = From p In info.Individuals
GridView1.DataSource = query
GridView1.DataBind()

我想知道如何将分页添加到此查询中,例如,在一个页面上,我曾尝试在GridView上使用内置分页,但这只会产生错误:

GridView 'GridView1‘触发了未处理的事件PageIndexChanging

当尝试切换到另一个页面时。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-02-01 21:09:39

好的,这很简单

在后台代码中处理PageIndexChanging事件,

C#

代码语言:javascript
复制
void GridView1_PageIndexChanging(Object sender, GridViewPageEventArgs e)
{
    //For example
    //Cancel the paging operation if the user attempts to navigate
    //to another page while the GridView control is in edit mode. 
    if (GridView1.EditIndex != -1)
    {
        // Use the Cancel property to cancel the paging operation.
        e.Cancel = true;

        // Display an error message.
        int newPageNumber = e.NewPageIndex + 1;
        Message.Text = "Please update the record before moving to page " +
        newPageNumber.ToString() + ".";
    }
    else
    {
        // Clear the error message.
        Message.Text = "";
    }
}

VB.NET

代码语言:javascript
复制
Private Sub GridView1_PageIndexChanging(sender As [Object], e As GridViewPageEventArgs)
    'For example
    'Cancel the paging operation if the user attempts to navigate
    'to another page while the GridView control is in edit mode. 
    If GridView1.EditIndex <> -1 Then
        ' Use the Cancel property to cancel the paging operation.
        e.Cancel = True

        ' Display an error message.
        Dim newPageNumber As Integer = e.NewPageIndex + 1
        Message.Text = "Please update the record before moving to page " & newPageNumber.ToString() & "."
    Else
        ' Clear the error message.
        Message.Text = ""
    End If
End Sub

您的标记将如下所示:

代码语言:javascript
复制
<asp:gridview id="GridView1" 
    autogeneratecolumns="true"
    emptydatatext="No data available." 
    allowpaging="true"
    autogenerateeditbutton="true"
    onpageindexchanging="GridView1_PageIndexChanging" 
    runat="server">
    <pagersettings mode="Numeric"
      position="Bottom"           
      pagebuttoncount="10"/>

    <pagerstyle backcolor="LightBlue"/>

  </asp:gridview>
票数 3
EN

Stack Overflow用户

发布于 2011-02-01 21:11:39

您需要一个方法来处理该事件。

代码语言:javascript
复制
/// <summary>
/// Handles the PageIndexChanging event.  
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The instance containing the event data.</param>    
public static void GridViewPageIndexChanging(object sender, GridViewPageEventArgs e)
{
    [your application functionality here]
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4862809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档