Wednesday, May 22, 2013

Auto Update A datagrid/Grdiview by Timer in asp.net C#

 using System.Data.SqlClient;
using System.Data;

 protected void Timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                BindGridView();
            }

            catch { }
        }
        #region Bind datagrid Grdiview
        private void BindGridView()
        {
            SqlDataAdapter adp = new SqlDataAdapter("Select * from TableName", mySqlConnection);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            try
            {
                DataView dv = new DataView(ds.Tables[0]);
                gdvListing.DataSource = dv;
                gdvListing.DataBind();
                if (gdvListing.Rows.Count <= 0)
                {
                    ltrErrorMsg.Text = "No Record Found.";
                }
            }
}

Click here to see ASPX html and Gridview Binding