“GridView1”触发了未处理的 PageIndexChanging 事件

发布于 2024-11-01 16:29:03 字数 4063 浏览 5 评论 0原文

我正在使用 gridview,我想使用分页。我已经将允许分页设置为 true,并将页面大小设置为 5。我可以看到 gridview 底部的数字,但是当我单击数字移动到相应页面时,它会抛出错误:

The GridView “GridView1”触发了未处理的事件 PageIndexChanging。

代码:

 <asp:GridView ID="GridView1" runat="server" CellPadding="5" 
    AutoGenerateColumns="False" AllowPaging="True" DataKeyNames="contact_id" 
    onrowcancelingedit="GridView1_RowCancelingEdit" 
    onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating" 
    PageSize="5">
    <Columns>
        <asp:TemplateField HeaderText="contact_id">
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Eval("contact_id") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="name">
            <ItemTemplate>
                <asp:Label ID="Label4" runat="server" Text='<%# Eval("name") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="address">
            <ItemTemplate>
                <asp:Label ID="Label5" runat="server" Text='<%# Eval("address") %>'></asp:Label><br />
                <asp:Label ID="Label6" runat="server" Text='<%# Eval("city") %>'></asp:Label><br />
                 <asp:Label ID="Label7" runat="server" Text='<%# Eval("state") %>'></asp:Label><br />
           <asp:Label ID="Label8" runat="server" Text='<%# Eval("pincode") %>'></asp:Label>

            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="email">
            <ItemTemplate>
                <asp:Label ID="Label9" runat="server" Text='<%# Eval("email") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="mobile">
            <ItemTemplate>
                <asp:Label ID="Label10" runat="server" Text='<%# Eval("mobile") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="context">
            <ItemTemplate>
                <asp:Label ID="Label11" runat="server" Text='<%# Eval("context") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="status">
            <ItemTemplate>
                <asp:Label ID="Label12" runat="server" Text='<%# Eval("status") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem>PENDING</asp:ListItem>
                <asp:ListItem>OK</asp:ListItem>
                </asp:DropDownList>
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Edit" ShowHeader="False">
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                    CommandName="Edit" Text="Edit"></asp:LinkButton>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update"></asp:LinkButton>
                &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                    CommandName="Cancel" Text="Cancel"></asp:LinkButton>
            </EditItemTemplate>
            <ItemStyle CssClass="button" />
        </asp:TemplateField>
    </Columns>
    <PagerStyle HorizontalAlign="Left" VerticalAlign="Middle" />
</asp:GridView>

I am using a gridview and I want to use paging. I have already set allow paging to true and page size to 5. I can see the numbers at the base of my gridview, but when i click on a number to move to respective page, it throws an error saying:

The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.

Code:

 <asp:GridView ID="GridView1" runat="server" CellPadding="5" 
    AutoGenerateColumns="False" AllowPaging="True" DataKeyNames="contact_id" 
    onrowcancelingedit="GridView1_RowCancelingEdit" 
    onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating" 
    PageSize="5">
    <Columns>
        <asp:TemplateField HeaderText="contact_id">
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Eval("contact_id") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="name">
            <ItemTemplate>
                <asp:Label ID="Label4" runat="server" Text='<%# Eval("name") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="address">
            <ItemTemplate>
                <asp:Label ID="Label5" runat="server" Text='<%# Eval("address") %>'></asp:Label><br />
                <asp:Label ID="Label6" runat="server" Text='<%# Eval("city") %>'></asp:Label><br />
                 <asp:Label ID="Label7" runat="server" Text='<%# Eval("state") %>'></asp:Label><br />
           <asp:Label ID="Label8" runat="server" Text='<%# Eval("pincode") %>'></asp:Label>

            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="email">
            <ItemTemplate>
                <asp:Label ID="Label9" runat="server" Text='<%# Eval("email") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="mobile">
            <ItemTemplate>
                <asp:Label ID="Label10" runat="server" Text='<%# Eval("mobile") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="context">
            <ItemTemplate>
                <asp:Label ID="Label11" runat="server" Text='<%# Eval("context") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="status">
            <ItemTemplate>
                <asp:Label ID="Label12" runat="server" Text='<%# Eval("status") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem>PENDING</asp:ListItem>
                <asp:ListItem>OK</asp:ListItem>
                </asp:DropDownList>
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Edit" ShowHeader="False">
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                    CommandName="Edit" Text="Edit"></asp:LinkButton>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update"></asp:LinkButton>
                 <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                    CommandName="Cancel" Text="Cancel"></asp:LinkButton>
            </EditItemTemplate>
            <ItemStyle CssClass="button" />
        </asp:TemplateField>
    </Columns>
    <PagerStyle HorizontalAlign="Left" VerticalAlign="Middle" />
</asp:GridView>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

靑春怀旧 2024-11-08 16:29:03

您必须处理网格的 PageIndexChanging 事件,

例如

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    //Bind grid

}

You will have to handle the PageIndexChanging event for the grid

Something like

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    //Bind grid

}
和影子一齐双人舞 2024-11-08 16:29:03

如果启用分页,它将不起作用。您还需要为 PageIndexChangeEvent 编写事件处理程序。检查此链接:http://forums.asp.net/post/1177923.aspx

It will not work if you enable paging. You also need to write the event handler for PageIndexChangeEvent. Check this link: http://forums.asp.net/post/1177923.aspx

醉南桥 2024-11-08 16:29:03

您需要编写“PageIndexChanging”事件才能使其工作。为 PageIndexChanging 添加事件处理程序,在其中设置 GridView.CurrentPage = e.NewPage...

You would need to code "PageIndexChanging" event to make it work. Add an event handler for the PageIndexChanging where you set the GridView.CurrentPage = e.NewPage...

摘星┃星的人 2024-11-08 16:29:03

在 HTML 标记中再添加一个事件以进行分页。

OnPageIndexChanging="GridView1_PageIndexChanging"

现在从后面的代码处理相同的事件

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    //Your code
}

Add one more event in HTML mark up for pagging.

OnPageIndexChanging="GridView1_PageIndexChanging"

Now handle same event from code behind

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    //Your code
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文