开发者

Gridview changing data with respect to time

I am working on Visual Studio 2010 and SQL Server 2008

I want to create an app in which my Gridview should change data (displayed in website开发者_Go百科) with respect to time


means say

col1  | col2 
name1 |  age1 
name2 |  age2 
name3 |  age3

after 10 sec say 
col1  | col2 
name4 |  age4 
name5 |  age5 
name6 |  age6

Can any one help me out?


the easiest way is to use the ASP.NET AJAX timer control: http://ajax.net-tutorials.com/controls/timer-control/ After 10 seconds, the tick event fires, and you can wrap everything in an UpdatePanel to give the user the full AJAX feel.

HTH.


Use Comet : Comet is a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it.

Creating Comet applications with ASP.NET
Scalable COMET Combined with ASP.NET

This code is not production ready; it is designed to demonstrate a theoretical solution to using COMET in ASP.NET. This article covers the server-side implementation of COMET and how to combat the scalability problems. To demonstrate the client code, I will release a smaller article soon which demonstrates a small tic-tac-toe game using the COMET thread pooling mechanism I mention below, which should give you some idea about using it in a real world application.


ASP.NET and Comet: Bringing Sockets Back
ASP.NET Comet Library


this i have done to achieve the above question to solve website1.aspx

<asp:ScriptManager ID="ScriptManager1" runat="server" />
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Timer ID="Timer1" runat="server" OnTick="UpdateTimer_Tick" Interval="5000">
                    </asp:Timer>
                      <Triggers>
                    <asp:AsyncPostBackTrigger controlid="Timer1" eventname="Tick" />
                          <asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="1" 
                              EnableModelValidation="True" AutoGenerateColumns="False">
                              <PagerSettings Visible="False" />
                              <columns>
                               <asp:ImageField DataImageUrlField="Image" >
                                   <ControlStyle Height="500px" Width="860px" />
                                  </asp:ImageField>
                              </columns>
                          </asp:GridView>

                          <br />
                </Triggers>
                </ContentTemplate>
                           </asp:UpdatePanel>

website1.aspx.cs

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
         LoadData();
    }

    protected void UpdateTimer_Tick(object sender, EventArgs e)
    {
        int pagecount = GridView1.PageCount;
         int pageIndex = GridView1.PageIndex;
         if (pageIndex != pagecount)
         {
             GridView1.PageIndex = pageIndex + 1;
             LoadData();
             Label1.Text = "" + GridView1.PageIndex++;

         }
         if (pageIndex == pagecount-1)
         {
             pageIndex = pageIndex - pagecount;
             GridView1.PageIndex = pageIndex + 1;
             LoadData();
             Label1.Text = "" + GridView1.PageIndex++;
         }

    }
    private void LoadData()
    {
        using (SqlConnection connection = new SqlConnection("Data Source=CJ-PC\\SQLEXPRESS;Initial Catalog=Online_Interaction;Integrated Security=True"))
        {
            using (SqlCommand command = new SqlCommand("Select [Image] from Picture_album", connection))
            {
                using (SqlDataAdapter da = new SqlDataAdapter(command))
                {
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }
            }
        }
    }

Thanx for helping stackoverflow

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜