Grid View

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sajitk
    New Member
    • Feb 2008
    • 77

    Grid View

    Guys,

    I have a grid view where i use the option of Editing a record. When i click on the edit button, Update and Cancel button appears.

    But when i click on the Update link, the event is not generated. I am not using templates, i am just using bounded fields.

    I have written the update program. Can anyone tell me the reason why this event is not fired. I have a primary key Sno, which is mentioned in the DatakeyName in the property box.

    Help would be appreciated.

    Code:
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            connstr = "server=.;uid=sa;pwd=sa;database=mydata";
            con = new SqlConnection(connstr);
            qry = "update  mytable set fname=@fnm, lname=@lnm where sno=@sn";
            cmd = new SqlCommand(qry, con);
    
            cmd.Parameters.Add(new SqlParameter("@sn", SqlDbType.Int));
            cmd.Parameters.Add(new SqlParameter("@fnm", SqlDbType.Char ,50));
            cmd.Parameters.Add(new SqlParameter("@lnm", SqlDbType.Char ,50));
            
            cmd.Parameters[0].Value = GridView1.DataKeys[e.RowIndex].Value;
            cmd.Parameters[1].Value = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text;
            cmd.Parameters[2].Value = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text;
            
            cmd.Connection.Open();
            cmd.ExecuteNonQuery();
            cmd.Connection.Close();
            GridView1.EditIndex = -1;
            fillGrid();
    
        }
    thanks / Sajit
Working...