I have a gridview rowCommand that will get the index of the row when fired. Then I need to retrieve all values of the index to be included in the where claws on the update statement of my button. I use multiple sessions to try that, but it's not working. Here's my code.
protected void gvawards_RowCommand(object sender, GridViewCommandEventArgs e)
{
btnsaveawards.Visible = true;
if (e.CommandName == "Name")
{
int index = Convert.ToInt32(e.CommandArgument);
dremployer2.SelectedItem.Text = gvawards.Rows[index].Cells[1].Text;
txtawardtitle.Text = gvawards.Rows[index].Cells[2].Text;
txtyearawarded.Text = gvawards.Rows[index].Cells[3].Text;
Session["Employer2"] = dremployer2.SelectedValue;
Session["Award"] = txtawardtitle.Text;
Session["YearAwarded"] = txtyearawarded.Text;
}
}
protected void btnsaveawards_Click(object sender, EventArgs e)
{
int employer2 = int.Parse(Session["Employer2"].ToString());
string awardtitle = Session["Award"].ToString();
int yearawarded = int.Parse(Session["YearAwarded"].ToString());
btnsaveawards.Visible = false;
con.Open();
string update = "update tblAwardsData set EmployerID='" + dremployer2.SelectedValue + "',AwardTitle='" + txtawardtitle.Text + "',YearAwarded='" + txtyearawarded.Text + "' where EmployerID='" + employer2 + "' and AwardTitle='" + awardtitle + "' and YearAwarded='" + yearawarded + "' and IDNumber='" + 11277718 + "'";
SqlCommand scmupdate = new SqlCommand(update, con);
scmupdate.ExecuteNonQuery();
view(); //Rebind the gridview
dremployer2.SelectedItem.Text = "Select employer";
txtawardtitle.Text = "";
txtyearawarded.Text = "".ToString(); ;
con.Close();
}