我有两个updatepanel,其中一个包含gridview。问题是分页只是第一次正常工作。
这是标记:
<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>
和背后的代码:
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#。
任何帮助都将受到高度赞赏。
此致 Kardo
答案 0 :(得分:3)
将UpdatePanel声明更改为如下所示:
<asp:UpdatePanel ID="upAnswers" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gvAnswers" EventName="PageIndexChanging" />
每当我遇到这些UpdatePanel
的问题时,我发现明确声明触发器有用。特别是当你使用“非默认”事件来触发AsyncPostBack时(SelectedIndexChanged是GridView的“默认”事件)。
此外,ChildrenAsTriggers默认为true,因此我从标记中删除了它。