Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Can anyone explain this coding step by step?

C#
protected void GridView1_RowUpdating1(object sender, GridViewUpdateEventArgs e)
   {
       int row = GridView1.EditIndex;
       GridViewRow rows = GridView1.Rows[e.RowIndex];
       if ((((TextBox)rows.FindControl("txtuser_name") != null) && (TextBox)rows.FindControl("txtpassword") != null))
       {
           int id = Convert.ToInt32(GridView1.DataKeys[row].Value.ToString());
           TextBox txtuser_name = (TextBox)rows.FindControl("txtuser_name");
           TextBox txtpassword = (TextBox)rows.FindControl("txtpassword");
           string user_name = txtuser_name.Text;
           string password = txtpassword.Text;
           con.Open();
           SqlCommand cmd = new SqlCommand("update login set user_name='" + user_name + "',password='" + password + "' where user_id=" + id + "", con);
           Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('Record Updated')</script>");
           cmd.ExecuteNonQuery();
           GridView1.EditIndex = -1;
           con.Close();
           bind_login();

       }
   }
Posted
Updated 14-Nov-11 17:59pm
v2

It's a bit of code that locates the username and password controls in a gridview, then updates the login table to set the user and password for the specified id. It's pretty nasty code in that it leaves the system open for a SQL injection attack...
 
Share this answer
 
step by step explanation

1. code called on "Row_Updating event"
2. collect the index of row which is updating
3. checks, row having username and password textboxes
4. collect text from textboxes using FindControl
5. open connection
6. update login table to set username and password using userid
7. execute Query and decrease edit index.
9. close connection and call bind_login() function.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900