GridView的'GridView1'触发了未处理的事件RowDeleting。 [英] The GridView 'GridView1' fired event RowDeleting which wasn't handled.
本文介绍了GridView的'GridView1'触发了未处理的事件RowDeleting。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我在.aspx页面中使用gridview,我想通过从gridview中选择id来删除记录。
下面是网格视图。想要删除行按删除。
Hi Everyone, i am using a gridview in my .aspx page,i want to delete the record by selecting the id from the gridview.
Below is grid view.and want to delete the row by pressing delete.
brand_id brand_name Brand Image
2 xyz 1 Select Delete
这是程序
如果@ xstatus = 3
begin
从品牌中删除brand_id = @ xbrand_id
这是我的代码
this is the procedure
else if @xstatus=3
begin
delete from brand where brand_id=@xbrand_id
and this is my code
if (e.CommandName == "Delete")
{
if (cn.State == ConnectionState.Closed)
{
cn.Open();
}
Session["brand_id"] = GridView1.Rows[index].Cells[0].Text;
{
string st = "delete from brand where brand_id=" + Session["brand_id"].ToString() + "";
SqlCommand cmd = new SqlCommand(st, cn);
cmd.Parameters.AddWithValue("@xstatus", 3);
cmd.ExecuteNonQuery();
branddata();
}
Session["brand_id"] = "";
代码是什么?请建议我。 ..thanku ....
what will be the code?please suggest me...thanku....
推荐答案
参考 - Asp.net在gridview中插入,编辑,更新,删除数据 [ ^ ]。
您应该为GridView
声明DataKey
。在RowDeleting
事件中,检索当前Row的DataKey
并按该ID删除行。
Refer - Asp.net insert, Edit, update, delete data in gridview[^].
You should have aDataKey
declared for theGridView
. Inside theRowDeleting
Event, retrieve the current Row'sDataKey
and delete the Row by that ID.
Quote:
int userid = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Values["UserId"].ToString());
string username = gvDetails.DataKeys[e.RowIndex].Values["UserName"].ToString();
con.Open();
SqlCommand cmd = new SqlCommand("delete from Employee_Details where UserId=" + userid, con);
int result = cmd.ExecuteNonQuery();
con.Close();
将此事件添加到您的代码中
Add this event to your code
protected void GridView1_rowdeleting(object sender, GridViewDeleteEventArgs e)
{
}
这篇关于GridView的'GridView1'触发了未处理的事件RowDeleting。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文