In my project i have request page that contain a datalist with four templates Image(profilepic),Label(firstname), and Button1(accept), button2(deny) and a hidden field that contains the address of requester
And written the code
protected void DataList1_ItemCommand(object source, 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();
}
}
}
On clicking on accept button the frnshpstatus in request table in Updated as ‘Y’ but it is still showing the accepted or deny requests in datalist.
I want them to remove only from datalist but keep the record of requests in database.
Answer in asp.net using c#.
Am I right in thinking you want the row completely removed from the datalist after clicking either accept or reject? If that’s the case just add a where clause to your query that populates the datalist
or whatever the default value is if not null. Then after you have completed the accept/reject process at the end of your ItemCommand event handler you’ll need to manually databind the datalist again