0

what is wrong with the code here... i am trying to update the values fetched in a row of a grid view by an edit,update,cancel command field button.

     protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    Label lblid = (Label)GridView1.Rows[e.RowIndex].FindControl("Elblid");
    TextBox txtuser = (TextBox)GridView1.Rows[e.RowIndex].FindControl("EtxtUserName");
    TextBox txtpass = (TextBox)GridView1.Rows[e.RowIndex].FindControl("EPassword");

    if (lblid.Text != "" || lblid.Text != null)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["con"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand("Update Login set UserName='" + txtuser.Text + "',Password='" + txtpass.Text + "' Where Id=" + lblid.Text, con);
        cmd.ExecuteNonQuery();
        con.Close();
        GridView1.EditIndex = -1;
        FillGrid();
    }

This was the error thrown :enter image description here

PS: when is set the event validation to be false in the page directives. this error disappeared but the code did nothing it was intended to.

Sunny
  • 91
  • 2
  • 13

1 Answers1

0

what error it is showing??

try this

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
    Label lblid = (Label)row.FindControl("Elblid");
    TextBox txtuser = (TextBox)row.FindControl("EtxtUserName");
    TextBox txtpass = (TextBox)row.FindControl("EPassword");
}
vikas
  • 23
  • 2
  • 10