datalist中实现删除一条数据的方法

在datalist中添加一个linkButton 点击删除对应的一条数据
2024-11-26 13:42:44
推荐回答(4个)
回答1:

aspx页面
LinkButton 包含在datalist中

'>删除

aspx.cs 页面
protected void lbtnDelete_Command(object sender, CommandEventArgs e)
{
//string userID = Request.QueryString["userID"]; //不好传送,试了N遍
string userID = e.CommandArgument.ToString();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = db.createCon();
cmd.CommandText = "delete from guest where ID='"+userID+"'";
if (cmd.ExecuteNonQuery() > 0)
{
Response.Write("");
}
else
{
Response.Write("");
}
}

回答2:

直接写sql语句就行了!

回答3:

这么抠?

回答4:

aspx页面
LinkButton
包含在datalist中
ID="lbtnDelete"
runat="server"OnCommand="lbtnDelete_Command"
Style="position:relative"
CommandArgument='<%#DataBinder.Eva(Container.DataItem,"ID")%>'>删除
aspx.cs
页面
protected
void
lbtnDelete_Command(object
sender,
CommandEventArgs
e)
{
//string
userID
=
Request.QueryString["userID"];
//不好传送,试了N遍
string
userID
=
e.CommandArgument.ToString();
OleDbCommand
cmd
=
new
OleDbCommand();
cmd.Connection
=
db.createCon();
cmd.CommandText
=
"delete
from
guest
where
ID='"+userID+"'";
if
(cmd.ExecuteNonQuery()
>
0)
{
Response.Write("");
}
else
{
Response.Write("");
}
}