首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用UpdatePanel刷新asp:webform中的ListView

使用UpdatePanel刷新asp:webform中的ListView
EN

Stack Overflow用户
提问于 2017-02-27 19:07:47
回答 1查看 512关注 0票数 0

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

代码语言:javascript
复制
<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>

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

EN

回答 1

Stack Overflow用户

发布于 2017-02-27 21:27:36

这里有两个不同的问题。

首先,TimerUpdatePanel之外,所以它当然会执行完整的PostBack。在UpdatePanel内移动计时器。

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

代码语言:javascript
复制
<asp:UpdatePanel runat="server" ID="Proc_UpdatePanel">
    <ContentTemplate>
        <asp:Timer runat="server" ID="UP_Timer" Interval="5000" OnTick="UP_Timer_Tick" />
    </ContentTemplate>
</asp:UpdatePanel>

代码隐藏:

代码语言:javascript
复制
protected void UP_Timer_Tick(object sender, EventArgs e)
{
    //update the ListView
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42484240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档