Email: Password:       Forgot Password 
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.

Automatically Referesh A GridView

Viewed:  2280 
Posted On:  02/09/2012 22:40:40 
How we can make a GridView referesh automatically.. 

In this article I am going to show how we can refresh a GridView after a particular time automatically.

This is my aspx code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <title>Auto Referesh Grid View</title>
    <form id="form1" runat="server">
        <table cellpadding="0" cellspacing="0" width="50%" align="center">
                    <asp:ScriptManager ID="ScriptManager1" runat="server" />
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                            <asp:Timer ID="AutoRefreshTimer" runat="server" Interval="1000" OnTick="AutoRefreshTimer_Tick" />
                            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%">
                                    <asp:BoundField DataField="FirstName" HeaderText="FirstName" />
                                    <asp:BoundField DataField="LastName" HeaderText="LastName" />
                                    <asp:BoundField DataField="JoiningDate" HeaderText="Joining Date" />
                            <asp:Label ID="lblMsg" runat="server" />


This is my aspx.cs code

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient; 

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

    private void BindData()
        SqlConnection con = new SqlConnection("Server=.;Database=MyData;Uid=sa; pwd=wintellect");
        SqlCommand cmd = new SqlCommand("SELECT *  FROM Employee", con);
            GridView1.DataSource = cmd.ExecuteReader();
        catch (Exception ex)
            lblMsg.Text = ex.Message;

    protected void AutoRefreshTimer_Tick(object sender, EventArgs e)

When I run the applciation


Figure 1. 

If user add a new row in this table then it refresh automatically ..


Figure 2.

         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us