里面的UpdatePanel的GridView寻呼不会为第二页变化工作,为什么? [英] GridView PAGING inside UpdatePanel does not work for second page change, why?
问题描述
我有两个的UpdatePanel这其中一个包含一个gridview。问题是分页正常工作只对第一次。
I got two updatepanels which one of them contains a gridview. The problem is the Pagination works properly only for the first time.
下面是标记:
<asp:UpdatePanel ID="upAnswers" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:GridView ID="gvAnswers" runat="server" CssClass="gv" Width="100%" ShowHeader="false" AllowPaging="True" PageSize="2" EnableSortingAndPagingCallbacks="true" OnPageIndexChanging="gvAnswers_PageIndexChanging" AutoGenerateColumns="False" AlternatingRowStyle-BackColor="#eee">
<Columns>
<asp:TemplateField HeaderText="Questions" ShowHeader="False">
<ItemTemplate>
<asp:Label ID="lblQuestions" onclick=<%# Eval("FaqID", "$('.lblAnswers_{0}').toggle('fast')") %> CssClass="block" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
<asp:Panel ID="pnlS1" runat="server" CssClass='<%# Eval("FaqID", "lblAnswers_{0}") %>' style="display: none;">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Question") %>' CssClass="block bold"></asp:Label>
<asp:Label ID="lblAnswers" runat="server" Text='<%# Eval("Answer") %>'></asp:Label>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="upgAnswers" runat="server" AssociatedUpdatePanelID="upAnswers" DisplayAfter="300">
<ProgressTemplate>
<div id="uiBlock" class="uiBlock">
</div>
</ProgressTemplate>
</asp:UpdateProgress>
和背后的code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetAnsweredPublicFAQs();
}
}
protected void GetAnsweredPublicFAQs()
{
DataSet ds = cFAQs.getAnsweredPublicFAQs();
gvAnswers.DataSource = ds;
gvAnswers.DataBind();
}
protected void gvAnswers_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvAnswers.PageIndex = e.NewPageIndex;
GetAnsweredPublicFAQs();
gvAnswers.DataBind();
upAnswers.Update();
}
作为参考,我使用ASP.NET 4.0 C#。
As ref, I use ASP.NET 4.0 C#.
任何种类的帮助将是非常美联社preciated。
Any kind help would be highly appreciated.
问候,
Kardo
Regards, Kardo
推荐答案
更改您的UpdatePanel声明开始是这样的:
Change your UpdatePanel declaration to start like this:
<asp:UpdatePanel ID="upAnswers" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gvAnswers" EventName="PageIndexChanging" />
每当我已经受够了这些的UpdatePanel
的烦恼,我发现明确声明触发器是有帮助的。尤其是当您使用的是非默认事件触发AsyncPostBack(的SelectedIndexChanged是默认事件,为GridView)。
Whenever I've had trouble with these UpdatePanel
s, I find explicitly declaring the Triggers to be helpful. Especially when you're using a "non-default" event to trigger an AsyncPostBack (SelectedIndexChanged is the "default" event for the GridView).
此外,ChildrenAsTriggers默认为true,所以我删除从标记。
Also, ChildrenAsTriggers defaults to true, so I removed that from the markup.
这篇关于里面的UpdatePanel的GridView寻呼不会为第二页变化工作,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!