How to refresh gridview after every insert command automatically?

Total Post:101

Points:709
C#
 1478  View(s)
Ratings:
Rate this:

I am inserting data to database when i click submit button data inserted into Database but no changes get reflected in GridView without refreshing the page.

  1. Post:378

    Points:2694
    Re: How to refresh gridview after every insert command automatically?

    Hi Pravesh, 


    public void GetData()        
        {
            try
            {
                SqlConnection connection = new SqlConnection();
                connection.ConnectionString = ConfigurationManager.ConnectionStrings["mysql"].ConnectionString;
                String sql= "Your Query";
                DataSet ds= new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(sql, connection);
                da.Fill(ds);
                DataTable dt = new DataTable();
                dt =ds.Tables[0];
                GridView1.DataSource = dt;
            }
            catch (SqlException ex)
            {
            }
            catch (Exception e)
            {
            }
        }

      Modified On Apr-05-2018 04:38:03 AM

Answer