在我的项目中,我有一个请求页面,其中包含一个数据列表,其中包含四个模板 Image(profilepic)、Label(firstname) 和 Button1(accept)、button2(deny) 和一个包含请求者地址的隐藏字段并编写了代码 protected void DataList1_ItemCommand(对象源,DataListCommandEventArgs e){
if (e.CommandName == "Accept")
{
SqlConnection con = new System.Data.SqlClient.SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["Con"].ConnectionString;
con.Open();
if (con.State == ConnectionState.Open)
{
HiddenField hd = (HiddenField)e.Item.FindControl("HiddenField1");
string str = hd.Value;
SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandText = "Update requests set frnshpstatus='Y' where Email='" + Session["UserName"] + "' And frnemail='" + str + "'";
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
else if (e.CommandName == "Deny")
{
SqlConnection con = new System.Data.SqlClient.SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["Con"].ConnectionString;
con.Open();
if (con.State == ConnectionState.Open)
{
HiddenField hd = (HiddenField)e.Item.FindControl("HiddenField1");
string str = hd.Value;
SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandText = "Update requests set frnshpstatus='N' where Email='" + Session["UserName"] + "' And frnemail='" + str + "'";
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
}
单击接受按钮时,请求表中的 frnshpstatus 已更新为“Y”,但仍显示数据列表中已接受或拒绝的请求。我希望他们只从数据列表中删除,但在数据库中保留请求记录。使用 c# 在 asp.net 中回答。