【问题标题】:Refreshing ListView in asp:webform using UpdatePanel使用 UpdatePanel 在 asp:webform 中刷新 ListView
【发布时间】:2017-07-17 23:27:12
【问题描述】:

我有一个列表视图,我想每 5 秒左右更新一次,更新面板会刷新但没有效果。

<asp:Timer runat="server" ID="UP_Timer" Interval="5000" />

<asp:UpdatePanel runat="server" ID="Proc_UpdatePanel">
    <ContentTemplate>
        <asp:ListView ID="ListView1" runat="server"
            DataKeyNames="procName"
            ItemType="SerMon.RemoteProcess" SelectMethod="fetchFromQueue">
            <EmptyDataTemplate>
                <table>
                    <tr>
                        <td>No data was returned.</td>
                    </tr>
                </table>
            </EmptyDataTemplate>
            <EmptyItemTemplate>
                <td />
            </EmptyItemTemplate>
            <LayoutTemplate>
                <table runat="server" id="table1" class="table table-striped table-hover ">
                    <thead>
                        <tr runat="server">
                            <th>#</th>
                            <th>Process</th>
                            <th>Status</th>
                            <th>Machine</th>
                        </tr>
                        <tr id="itemPlaceholder" runat="server"></tr>
                    </thead>
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <tr runat="server">
                    <td>1</td>
                    <td>
                        <asp:Label runat="server" ID="lblId"><%#: Item.ProcName%></asp:Label></td>
                    <td>
                        <asp:Label runat="server" ID="Label1"><%#: Item.Procstatus%></asp:Label></td>
                    <td>
                        <asp:Label runat="server" ID="Label2"><%#: Item.mcName%></asp:Label></td>
                </tr>
            </ItemTemplate>
        </asp:ListView>
    </ContentTemplate>
</asp:UpdatePanel>

整个页面刷新,但没有调用填充列表视图的方法。我哪里错了?

【问题讨论】:

  • 看这个stackoverflow.com/questions/23137073/…>

标签: c# asp.net listview webforms updatepanel


【解决方案1】:

这里有两个不同的问题。

首先TimerUpdatePanel之外,所以它当然会做一个完整的PostBack。在 UpdatePanel 中移动计时器。

其次,您没有为计时器指定OnTick 事件。没有它,Timer 只会刷新页面。

<asp:UpdatePanel runat="server" ID="Proc_UpdatePanel">
    <ContentTemplate>
        <asp:Timer runat="server" ID="UP_Timer" Interval="5000" OnTick="UP_Timer_Tick" />
    </ContentTemplate>
</asp:UpdatePanel>

后面的代码:

protected void UP_Timer_Tick(object sender, EventArgs e)
{
    //update the ListView
}

【讨论】:

    猜你喜欢
    • 2015-05-29
    • 1970-01-01
    • 1970-01-01
    • 2011-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多