PankaJ D

PankaJ D

  • NA
  • 154
  • 0

upadating record in gridview

Jan 4 2011 4:25 AM
I am trying to update record in grid view using following commmand.But it does not Update the record.

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
Label lbl = (Label)row.FindControl("label8");
TextBox txtq = (TextBox)row.FindControl("TextBox7");


GridView1.EditIndex = -1;
cn.Open();

string sql = "UPDATE Q_Master SET Que = '" + txtq.Text + " ' WHERE Q_id='" + lbl.Text + "' ";
SqlCommand cmd = new SqlCommand(sql, cn);

cmd.ExecuteNonQuery();
cn.Close();
LoadBind();
}

LoadBind()
{
string sql = "SELECT * FROM Q_Master";

SqlCommand cmd = new SqlCommand(sql, cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);

da.Fill(ds, "Q_Master");
GridView1.DataSource = ds;
GridView1.DataBind();
}

Answers (4)