如题,点击刷新是可以更新的,但是不能自动更新,不知道哪里有问题?<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Timer Messages</title>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="sm1" runat="server" />
    
    <asp:Timer ID="Timer1" Interval="5000" runat="server" />
    
    <asp:UpdatePanel ID="up1" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
    </Triggers>
    <ContentTemplate>
    Last Refresh <%= DateTime.Now.ToString("T") %>
    
    <asp:gridview
        id="grdview1"
        DataSourceID="srcMessages"
        Runat="server" />        
     
    <asp:sqldatasource
        id="srcMessages"
        connectionstring='<%$ connectionStrings:con %>'
        selectcommand="select * from message" 
        Runat="server" />       </ContentTemplate>      
    </asp:UpdatePanel>
  
    </div>
    </form>
</body>
</html>

解决方案 »

  1.   

    数据更新后要重新绑定...GridView1.DataSource = ...
    GridView1.DataBind();
      

  2.   

    this.GridView1.DataBind();
    //updatePanel也更新一下试试
    this.up1.Update()
      

  3.   

    重新绑定一下就可以了this.GridView1.DataBind();
      

  4.   

    重新绑定!!GridView.DataSource = ...;
    GridView.DataBind();
      

  5.   

    更新操作语句之后
    加上  DataBind() 就可以了
      

  6.   


    我通过update panel和trigger更新,不知道该在哪里重新绑定呢?
      

  7.   

    在视图里面双击Timer1
    在里面写
    GirdView1.datasouce=;
    Gridview1.databind();
      

  8.   

    需添加timer1的tick事件,如下,谢谢楼上,<%@ Page Language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">    protected void Timer1_Tick(object sender, EventArgs e)
        {
            gridview1.DataBind();
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Timer Messages</title>
        
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:ScriptManager ID="sm1" runat="server" />
        
        <asp:Timer ID="Timer1" Interval="5000" runat="server" ontick="Timer1_Tick" />
        
        <asp:UpdatePanel ID="up1" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
        </Triggers>
        <ContentTemplate>
        Last Refresh <%= DateTime.Now.ToString("T") %>
        
        <asp:gridview
            id="gridview1"
            DataSourceID="srcMessages"
            Runat="server" />        
        
        
        <asp:sqldatasource
            id="srcMessages"
            connectionstring='<%$ connectionStrings:con %>'
            selectcommand="select * from message order by id desc" 
            Runat="server" />   
        </ContentTemplate>      
        </asp:UpdatePanel>
            </div>
        </form>
    </body>
    </html>