删除命令后,网格视图不会更新(即只有fornt结束) [英] Grid view not aupdating(i.e only fornt end) after delete command
本文介绍了删除命令后,网格视图不会更新(即只有fornt结束)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void filladapter()
{
da.DeleteCommand = new SqlCommand();
da.DeleteCommand.Connection = con;
da.DeleteCommand.CommandText = "DELETE FROM [dbo].[Customer] WHERE ([CustomerId] = @CustomerId)";
da.DeleteCommand.CommandType = CommandType.Text;
da.DeleteCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerId", System.Data.SqlDbType.BigInt, 0, System.Data.ParameterDirection.Input, 0, 0, "CustomerId", System.Data.DataRowVersion.Current, false, null, "", "", ""));
da.InsertCommand = new SqlCommand();
}
private void showAllCustomer()
{
SqlConnection con = new SqlConnection(Connection.getConnectionSource());
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Customer";
cmd.Connection = con;
da.SelectCommand = cmd;
da.Fill(dt);
bsource.DataSource = dt;
datagdvCustomer.DataSource = bsource;
}
//..........................delete commnad...................................................//
string ctid = datagdvCustomer.Rows[e.RowIndex].Cells["CustomerId"].Value.ToString();
filladapter();
con.Open();
da.DeleteCommand.Parameters["@CustomerId"].Value = ctid;
da.DeleteCommand.ExecuteNonQuery();
con.Close();
datagdvCustomer.DataSource = null;
showAllCustomer();
It is showing records twice,and that too without updation ....backend is updation is correct
推荐答案
您可以使用
OnRowDeleting GRIDVIEW的属性
You can use
OnRowDeleting property of GRIDVIEW
//Function To delete records from grid view
protected void Countrylist_Rowdelete(object sender, GridViewDeleteEventArgs e)
{
int intCode = Convert.ToInt32(Countrylist.DataKeys[e.RowIndex].Value);//here it will get the row selected to delete
string strQuery = "DELETE FROM Country_master " +
"WHERE CountryId=" + intCode + "";
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
OleDbCommand oledbcmd = new OleDbCommand(strQuery, con);
oledbcmd.ExecuteNonQuery();
Display();//Your Gridview Bind function
}
您可以在PageLoad()上调用您的显示器()..
希望这有助于!!
You can call Your Display() On PageLoad()..
Hope This Helps!!
试试这个
Try this
private void showAllCustomer()
{
SqlConnection con = new SqlConnection(Connection.getConnectionSource());
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Customer";
cmd.Connection = con;
da.SelectCommand = cmd;
//You need tocreate fresh datatable object here. I think your datatable object is public & mantaining values
DataTable dt = new DataTable();
da.Fill(dt);
bsource.DataSource = dt;
datagdvCustomer.DataSource = bsource;
}
这篇关于删除命令后,网格视图不会更新(即只有fornt结束)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文