[英]update panel is updating entire page instead of just grid view
我正在尝试使用ajax计时器和更新面板来仅更新我的gridview,但是它一直在重置整个页面。 我究竟做错了什么? 这是我的代码。
aspx页面:
<div class="row text-center">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="gvShowContent" />
</Triggers>
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="60000" OnTick="Timer1_Tick"></asp:Timer>
<asp:GridView ID="gvShowContent" runat="server" OnRowCommand="gvShowContent_RowCommand" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Course_Code" HeaderText="Course Code" />
<asp:BoundField DataField="Content_Name" HeaderText="Title" />
<asp:BoundField DataField="Content_Description" HeaderText="Description" />
<asp:BoundField DataField="Content_Title" HeaderText="File Name" />
<asp:TemplateField HeaderText="Download">
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" runat="server" CommandArgument='<%# Eval("Content_Title") %>' CommandName="cmd">Download</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
代码背后:
protected void Timer1_Tick(object sender, EventArgs e)
{
gvShowContent.DataSource = proxy.ShowContent();
gvShowContent.DataBind();
}
无需在UpdatePanel中<trigger>
GridView: https : //msdn.microsoft.com/zh-cn/library/cc295400.aspx
因此,删除此:
<Triggers>
<asp:PostBackTrigger ControlID="gvShowContent" />
</Triggers>
现在绑定并更新您的UpdatePanel:
protected void Timer1_Tick(object sender, EventArgs e)
{
gvShowContent.DataBind();
UpdatePanel1.Update();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.