Google Search

Wednesday, October 31, 2007

Realtime Cricket Scores using ASP.NET AJAX

This is the application I built using ASP.NET AJAX using the RSS feeds of CricInfo(dont know if it is legal).

The scores gets updated without you refreshing.

After you have installed the ASP.NET AJAX create a new ASP.NET AJAX Enabled Web site.

In the Default.aspx page:

Put a Script Manager control from the AJAX server controls

Then add an Update Panel control from the same AJAX server controls.

Inside Update Panel Add the following controls:

Timer (AJAX) (set the interval to 10000 (10 secs))
A gridView control (set the Visible property to false)
and two Labels(one showing current time, other one showing the score)

Note: All these should be inside a tag.

Now in the Page_Load of default.aspx.cs:


DataSet ds = new DataSet();
ds.ReadXml("http://www.cricinfo.com/rss/livescores.xml");
GridView1.DataSource = ds.Tables[2];
GridView1.DataBind();
lblTime.Text = DateTime.Now.ToString();
lblScore1.Text = GridView1.Rows[0].Cells[2].Text;

Double click the Timer control:
In the Timer1_Tick event:

lblTime.Text = DateTime.Now.ToString();
lblScore1.Text = GridView1.Rows[0].Cells[2].Text;