we want to accept only one record in gridview through accept button but in our code all requests are accepted if we are on last record.kindly let me know the problem in my code also provide the solution
protected void ChangeStatus(object sender, EventArgs e) { var context = new healthCareContext();
Button btn = (Button)sender;
string str = btn.CommandName;
var pemail = str;
//////int row = GridView1.Rows.Count;
////GridView1.SelectedIndex =GridView1.Rows.Count;
////string mypemail = GridView1.SelectedRow.Cells[2].Text;
String status="Accepted";
if (btn.Text == "Accepted")
btn.Visible = false;
string newStatus = "";
if (btn.Text == "Accept")
{
newStatus = "Accepted";
Response.Write("appointment has been Accepted and added in the database table 'appointments'.");
}
using (context)
{
var results = (from a in context.appointments where a.pemail == pemail select a);
foreach (var b in results)
{
b.astatus = newStatus;
//string signupName = b.name;
}
//int row = GridView1.Rows.Count;
//GridView1.Selected
// string mypemail = GridView1.SelectedRow.Cells[2].Text;
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["healthCareContext"].ConnectionString);
conn.Open();
Console.WriteLine(conn);
SqlCommand com = new SqlCommand("INSERT into appointments (astatus) values (@p1) where pemail==" + pemail + "), conn");
com.Parameters.AddWithValue("@p1", status);
com.ExecuteNonQuery();
conn.Close();
context.SaveChanges();
}
Response.AppendHeader("Refresh", "0");
}
the html markup
' onClick="ChangeStatus"> " SelectCommand="SELECT * FROM [appointments]">
GridView's html mark-up. - SelvaS