我更新行时如何刷新gridview? [英] How i refresh gridview when i update row ?

查看:69
本文介绍了我更新行时如何刷新gridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  private   void  btn_Edit_Click(对象发​​件人,EventArgs e)
{
con.Open();
使用(sd = new SqlCommand( <跨度类= 代码串>更新Auto_Part_Details设置Value_Part =
@Value_Part,Auto_Parts_id = @Auto_Parts_id,Repair_id = @Repair_id,
New_Old_Part = @New_Old_Part,PROVIDER_ID = @Provider_id,
Installation_id = @Installation_id,注释= @Notes其中Job_Card =
@Job_Card,CON))
{
sd.Parameters.AddWithValue(<跨度类= code-string>
@ Job_Card,txt_Job_card.Text);
sd.Parameters.AddWithValue( @ Value_Part,txt_Value_Part.Text);
sd.Parameters.AddWithValue(<跨度类= 代码串> <跨度类= 代码串 > @ Auto_Parts_id
Convert.ToInt32 (CB_Auto_parts.SelectedValue));
sd.Parameters.AddWithValue( @ Repair_id
Convert.ToInt32 (CB_Repair_type.SelectedValue));
sd.Parameters.AddWithValue( @ New_Old_Part,Convert.ToBoolean(x)) ;
sd.Parameters.AddWithValue(<跨度类= 代码串> <跨度类= 代码串 > @ PROVIDER_ID
Convert.ToInt32 (CB_Providers_desc.SelectedValue));
sd.Parameters.AddWithValue(<跨度类= 代码串> <跨度类= 代码串 > @ Installation_id
Convert.ToInt32 (CB_Hand_installation.SelectedValue));
sd.Parameters.AddWithValue( @ Notes,txt_Notes.Text);
}

sd.ExecuteNonQuery();
con.Close();
}





我的尝试:



i创建网格视图以显示数据,当我更新任何行时,我刷新在网格视图中显示的数据?

解决方案

你必须重新绑定你的gridview在执行

 sd.ExecuteNonQuery(); 

之后填充数据,调用你的gridview绑定数据的方法。如果有任何疑问,请再问一遍。快乐编码<!/ BLOCKQUOTE>

private void btn_Edit_Click(object sender, EventArgs e)
        {
            con.Open();
                using (sd = new SqlCommand("update Auto_Part_Details set Value_Part= 
                @Value_Part, Auto_Parts_id = @Auto_Parts_id, Repair_id = @Repair_id, 
                New_Old_Part = @New_Old_Part ,Provider_id = @Provider_id , 
                Installation_id = @Installation_id , Notes = @Notes where Job_Card = 
                @Job_Card", con))
                {
                    sd.Parameters.AddWithValue("@Job_Card", txt_Job_card.Text);
                    sd.Parameters.AddWithValue("@Value_Part", txt_Value_Part.Text);
                    sd.Parameters.AddWithValue("@Auto_Parts_id", 
                    Convert.ToInt32(CB_Auto_parts.SelectedValue));
                    sd.Parameters.AddWithValue("@Repair_id", 
                    Convert.ToInt32(CB_Repair_type.SelectedValue));
                    sd.Parameters.AddWithValue("@New_Old_Part", Convert.ToBoolean(x));
                    sd.Parameters.AddWithValue("@Provider_id", 
                    Convert.ToInt32(CB_Providers_desc.SelectedValue));
                    sd.Parameters.AddWithValue("@Installation_id", 
                    Convert.ToInt32(CB_Hand_installation.SelectedValue));
                    sd.Parameters.AddWithValue("@Notes", txt_Notes.Text);
                }

                sd.ExecuteNonQuery();
                con.Close();
        }



What I have tried:

i create grid view to display data which i refresh data that display in grid view when i updata any row ?

解决方案

You have to re-bind your gridview to populate data after executing

sd.ExecuteNonQuery();

call the method in which you have bind data with your gridview.If any query then please ask again.Happy coding!


这篇关于我更新行时如何刷新gridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆