2015-10-03 50 views
0

我在asp.net頁面中有一個gridview。當我將數據插入gridview時,整個頁面將重新加載。如何避免這種情況?這裏是我的代碼如何避免在將數據插入到gridview後重新加載頁面

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; 
    string details = (control.FindControl("txtdetails") 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,@details,@SlNo)"; 
      cmd.Parameters.AddWithValue("@SlNo", SlNo); 
      cmd.Parameters.AddWithValue("@Code", Code); 
      cmd.Parameters.AddWithValue("@details", details); 
      con.Open(); 
      cmd.ExecuteNonQuery(); 
      con.Close(); 
     } 
    } 
    Response.Redirect(Request.Url.AbsoluteUri); 
} 

回答

1

我認爲,這個問題事業的Response.Redirect(Request.Url.AbsoluteUri);所以,你需要在函數完成後指定它,它可能會解決你的問題。

+0

我已刪除該代碼,仍然是同樣的問題,而我點擊添加按鈕數據插入和wholw頁面刷新。我在同一頁面的某些文本框中鍵入數據,這些數據也被刪除。我該如何解決這個問題? –

相關問題