【问题标题】:update panel is updating entire page instead of just grid view更新面板正在更新整个页面,而不仅仅是网格视图
【发布时间】:2018-05-21 18:25:45
【问题描述】:

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

【问题讨论】:

    标签: c# asp.net ajax timer updatepanel


    【解决方案1】:

    UpdatePanel 中无需&lt;trigger&gt;GridView:https://msdn.microsoft.com/en-us/library/cc295400.aspx

    所以删除这个:

    <Triggers>
        <asp:PostBackTrigger ControlID="gvShowContent" />
    </Triggers>
    

    现在绑定并更新您的 UpdatePanel:

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

    【讨论】:

      猜你喜欢
      • 2015-09-06
      • 2014-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-08
      • 1970-01-01
      相关资源
      最近更新 更多