从另一个表单提交对gridview的更改

本文关键字:gridview 另一个 表单提交 | 更新日期: 2023-09-27 18:07:57

我有一个表单1,其中包括一个绑定到客户表的网格视图,当用户双击网格视图行时,会显示一个新的表单2,并允许用户修改数据。当用户修改数据并单击表单2中的"保存"按钮时,它会将更改保存到数据库中,但在表单1重新打开之前,更改不会显示在表单1的网格视图中。为什么?

//FORM1 when user double click on rows to edit 
private void radGridView1_CommandCellClick(object sender, EventArgs e)
{
    GridCommandCellElement gCommand = (sender as GridCommandCellElement);     
    string v = gCommand.RowInfo.Cells["CustomerID"].Value.ToString();
    Form2 f2 = new Form2(v);
    f2.Show(this);
}
//FORM2 when user click on save button
private void button1_Click(object sender, EventArgs e)
{
    using (SqlConnection con = new SqlConnection(WindowsFormsApplication4TELERIK.Properties.Settings.Default.NorthwindConnectionString))
    {
       con.Open();
       using (SqlTransaction tran =con.BeginTransaction(IsolationLevel.Serializable))
       {
          SqlCommand cmd = con.CreateCommand();
          cmd.CommandText = "update customers set CompanyName='" + this.radTextBoxControl1.Text +"'";
          tran.Commit();
          cmd.ExecuteNonQuery();
       }
    }
    this.Close();
}

从另一个表单提交对gridview的更改

它并不像我们想象的那么简单。

下面的链接中提到了一种简单的方法。只需按照其中提到的步骤操作即可。

从Form 2 刷新GridView