How to use Timer in asp.net ajax

Timer in asp.net ajax
UsingTimer.aspx

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Configuration" %>

<!DOCTYPE html>
<script runat="server">
    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GridView1.DataSourceID = "SqlDataSource1";
            GridView1.DataBind();
            GridView1.SelectedIndex = 0;
        }
    }
    protected void Timer1_Tick(object sender, System.EventArgs e)
    {
        int selectedRow = GridView1.SelectedIndex;
        GridView1.SelectedIndex = selectedRow + 1;
        if (selectedRow == 9)
        {
            GridView1.SelectedIndex = 0;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "Button clicked but GridView SelectedIndex not reset";
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Ajax Timer - How to use Timer in asp.net ajax</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:DarkBlue; font-style:italic;">Ajax Timer Example: How To Use Timer In ASP.NET Ajax</h2>
        <hr width="550" align="left" color="CornFlowerBlue" />
        <asp:ScriptManager 
            ID="ScriptManager1"
            runat="server"
            >
        </asp:ScriptManager>
        <asp:SqlDataSource 
            ID="SqlDataSource1"
            runat="server"
            DataSourceMode="DataReader"
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="Select Top 9 ProductID, ProductName, UnitPrice From Products"
            >
        </asp:SqlDataSource>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:GridView 
                    ID="GridView1"
                    runat="server"
                    ForeColor="Snow"
                    BackColor="OrangeRed"
                    BorderColor="Orange"
                    Font-Names="Comic Sans MS"
                    Width="550"
                    >
                    <SelectedRowStyle 
                        ForeColor="Snow" 
                        BackColor="Orange" 
                        Height="35" 
                        Font-Italic="true"
                        />
                    <HeaderStyle BackColor="IndianRed" Height="40" />
                </asp:GridView>
                <asp:Timer 
                    ID="Timer1"
                    runat="server"
                    Interval="2000"
                    OnTick="Timer1_Tick"
                    >
                </asp:Timer>
                <br />
                <asp:Label 
                    ID="Label1" 
                    runat="server" 
                    Text="Test Label"
                    ForeColor="DodgerBlue"
                    Font-Size="Medium"
                    Font-Names="Comic Sans MS"
                    >
                </asp:Label>
                <br /><br />
                <asp:Button 
                    runat="server" 
                    ID="Button1" 
                    Text="Click me after 5 seconds" 
                    OnClick="Button1_Click"
                    Font-Bold="true"
                    ForeColor="SeaGreen"
                    Height="45"
                    />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>
Related asp.net ajax examples