- Category: ASP.Net
- Published on Sunday, 17 April 2011 05:13
- Written by Shabdar
- Hits: 10285
It always made me wonder how sites like http://finance.yahoo.com and http://finance.google.com display stock quotes online so quickly and without refreshing entire page. So I decided to implement something similar. It looks very difficult to implement these kind of streaming, but ASP.Net and it's feature rich AJAX controls makes it really simple to implement this. This is my first attempt to build similar streaming web page. This sample may sound fairly easy to you and some of you might think that everyone knows this. But it might provide a good base for those who wants to build similar web sites and still have no idea where to start.
Sample code provided in this article includes a web page Default.aspx and Default.aspx.cs code behind.
Default.aspx.cs (Code Behind)
GetGridData() function simulates quotes for different stock symbols. Instead of simulated data you can replace this function to fetch real time quotes from other sources. This function builds a data table using random quotes and returns it.
Timer1_Tick() function is a timer function which executes every 2 seconds. It rebinds grid with simulated stock data.
Points of Interest
As you can see here, I am using a simulation for stock quotes. It would be interesting to know how can we fetch real time quotes from Yahoo/Google or any other source.
These are few links I have found which discusses this,