本文介绍了在网格视图中删除一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经编写了使用Grid View删除数据库表中的行的代码.但是问题是该行没有被删除.我在Grid View中看不到数据的任何变化.我在哪里出错,请提供正确的代码,这是我的代码
i have written code for deleting a row in a database table using Grid View. But the problem is the row is not getting deleted. I donot see any changes in the data in Grid View.Where am i wrong,help me with the correct code.Here is my code
protected void DeleteRecord(object sender, GridViewDeleteEventArgs e)
{
string id = gridRegistrationTableDetails.Rows[e.RowIndex].Cells[0].Text;
deleterecordMethod(id);
BindData();
}
private void deleterecordMethod(string id)
{
string Query = "delete from SignUp where Employee_ID=@EmpID";
try
{
SqlConObject.Open();
SqlCommand cmd = new SqlCommand(Query, SqlConObject);
cmd.Parameters.AddWithValue("@EmpID", id);
cmd.ExecuteNonQuery();
}
catch(Exception e)
{
Response.Write("<script>alert('Exception Occurred')</script>"+e);
}
finally
{
SqlConObject.Close();
}
}
推荐答案
private void deleterecordMethod(string id)
{
string Query = "delete from SignUp where Employee_ID=@EmpID";
try
{
SqlConObject.Open();
SqlCommand cmd = new SqlCommand(Query, SqlConObject);
cmd.Parameters.AddWithValue("@EmpID", id);
cmd.ExecuteNonQuery();
//Call your FillGrid() method here to see effect in gridview.
}
catch(Exception e)
{
Response.Write("<script>alert('Exception Occurred')</script>"+e);
}
finally
{
SqlConObject.Close();
}
}
protected void DeleteRecord(object sender, GridViewDeleteEventArgs e)
{
string id = gridRegistrationTableDetails.Rows[e.RowIndex].Cells[0].Text;
deleterecordMethod(id);
BindData();
}
private void deleterecordMethod(string id)
{
try
{
SqlConObject.Open();
SqlCommand cmd = new SqlCommand("delete from SignUp where Employee_ID=@EmpID", SqlConObject);
cmd.Parameters.AddWithValue("@EmpID", id);
cmd.ExecuteNonQuery();
}
catch(Exception e)
{
Response.Write("<script>alert('Exception Occurred')</script>"+e);
}
finally
{
SqlConObject.Close();
}
}
让我知道它是否对您有帮助.
--Amit
Let me know if it helps you..
--Amit
这篇关于在网格视图中删除一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!