Sivajihero Hero

Sivajihero Hero

  • NA
  • 105
  • 32.4k

After inserting data into the gridview page reloading

Oct 5 2015 3:00 AM
I have a gridview in my asp.net website. When I insert data into the gridview the whole page is reloading. Ho wcan I avoid this?
Here is my code

 protected void AddNewCustomer(object sender, EventArgs e)
    {
        Control control = null;
        if (GridView1.FooterRow != null)
        {
            control = GridView1.FooterRow;
        }
        else
        {
            control = GridView1.Controls[0].Controls[0];
        }
        string SlNo = (control.FindControl("txtSlNo") as TextBox).Text;
        string Code = (control.FindControl("txtcode") as TextBox).Text;
     
        using (SqlConnection con = new SqlConnection(""))
        {

            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.Connection = con;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "INSERT INTO [Qtattemp] VALUES(@Code,@SlNo)";
                cmd.Parameters.AddWithValue("@SlNo", SlNo);
                cmd.Parameters.AddWithValue("@Code", Code);
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
            }
        }
     


Answers (7)