在AJAX更新面板里面,asp.net gridview中的分页不起作用 [英] Paging not working in asp.net gridview inside AJAX updatepanel

查看:147
本文介绍了在AJAX更新面板里面,asp.net gridview中的分页不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个最初绑定到sqldatasource控件的asp.net gridview,但是当用户按下一个外部按钮时,它会获取数据表的内容而不是SQLdatasource控件。因此,我必须在GridView的PageIndexChanging事件中编写代码以允许分页。我的代码如下:

I have an asp.net gridview that is originally bound to a sqldatasource control, but when the user presses an external button, it instead gets the contents of a datatable rather than a SQLdatasource control. I therefore had to write code in the PageIndexChanging event of the gridview to allow for paging. My code is as follows:

Protected Sub gvEvents_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvEvents.PageIndexChanging

gvEvents.PageIndex = e.NewPageIndex

gvEvents.DataBind()

直到我添加了一个AJAX更新面板,这样整个页面在每次分页时都不会回发,并且分页停止工作。我调试了它,发现它实际上正在调用PageIndexChanging事件,但没有发生任何事情。

This worked beautifully until I added an AJAX update panel so the whole page wouldn't postback every time it paged, and paging stopped working. I debugged it and discovered that it is actually calling the PageIndexChanging event, but nothing is happening.

我搜索了网页,发现有几个人有同样的问题,但是他们的解决方案对我无效。在这个网站上有一个问题是通过以下方式解决的:

I searched the web and found a few people with the same problem, but their solutions did not work for me. There was one on this site whose problem was solved by the following:


在PageIndexchanging事件中,将数据绑定到网格的地方,数据再次从数据库中获取

In PageIndexchanging event, where you bind data to grid, make sure, data is again fetched from the DB

我不知道这意味着什么;我的数据被绑定如上所示。我已将启用分页设置为true,并将EnableSortingAndPagingCallbacks设置为false。

I don't know what that means; my data was being bound as demonstrated above. I have "enable paging" set to true and EnableSortingAndPagingCallbacks set to false.

如果有人可以帮助我,我将非常感激。我在下面的updatepanel中包含了我的标记。

I would really appreciate if someone can help me. I am including my markup for the updatepanel below. Thank you so much!

    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ibtnSearch" />           
        </Triggers>

        <ContentTemplate>

            <asp:GridView ID="gvEvents" runat="server"  DataKeyNames = "intID"
                AutoGenerateColumns="False" AllowPaging="True" GridLines="None" CellPadding="10" 
                ForeColor="#333333" PageSize="6" DataSourceID="defaultDS" >
                <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />

                <Columns>
                    <asp:TemplateField HeaderText="Date">
                        <ItemTemplate>
                        <!-- put code block inside label? To set the formatter to include year if 
                        it's next year? -->
                        <asp:Label ID="Label1" runat="server" 
                            Text = '<%# RepeatingMethods.DetermineOngoing(CType(Eval("dtmEventStartDate"), DateTime) , CType(Eval("dtmEventEndDate"), DateTime))%>'> </asp:Label>

                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                  <ItemTemplate>
                  <asp:Label ID="Label4" runat="server" Text='<%# Eval("chvAgeRange")  %>'> </asp:Label> <br />
                   <asp:Label ID="Label3" runat="server" Text= '<%# Eval("chvState")  %>'> </asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:HyperLinkField DataNavigateUrlFields="intId" 
                    DataNavigateUrlFormatString="EventDetail.aspx?intId={0}" 
                    DataTextField="chvEventName" />

                    <asp:BoundField DataField="chvBriefDescription" HeaderText="Description" 
                        SortExpression="chvBriefDescription" />


            </Columns>
                     <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                     <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                     <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                     <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                     <AlternatingRowStyle BackColor="White" />


<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White"></FooterStyle>

<PagerStyle HorizontalAlign="Center" BackColor="#FFCC66" ForeColor="#333333"></PagerStyle>

<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy"></SelectedRowStyle>

<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White"></HeaderStyle>

<AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
    </asp:GridView>



                <asp:Label ID="lblError" runat="server"></asp:Label>

    <br />
    </ContentTemplate>
    </asp:UpdatePanel>


推荐答案

对于遇到此问题的人,我遇到过这个AM和这篇文章是误导性的(至少为我的情况)。对我来说,我只需添加一个PageIndexChanging事件作为updatepanel触发器的datagrid的触发器,并解决了我的问题。

For anyone who stumbles across this issue, I encountered it this AM and this post was misleading (atleast for my scenario). For me, I simply had to add a PageIndexChanging Event as a trigger for my datagrid for the updatepanel trigger's, and it resolved my issue.

这篇关于在AJAX更新面板里面,asp.net gridview中的分页不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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