更新面板正在更新整个页面而不仅仅是网格视图

时间:2017-12-07 15:37:13

标签: c# asp.net ajax timer updatepanel

我尝试使用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();
    }

1 个答案:

答案 0 :(得分:0)

UpdatePanel中不需要<Triggers> <asp:PostBackTrigger ControlID="gvShowContent" /> </Triggers> GridView:here

所以删除它:

protected void Timer1_Tick(object sender, EventArgs e)
{
    gvShowContent.DataBind();
    UpdatePanel1.Update();
}

现在绑定并更新您的UpdatePanel:

{{1}}
相关问题