How to Edit a gridview ,Please correct the code which i gave here.
-
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { //TextBox t= (TextBox )GridView1.Rows[e.RowIndex ].FindControl ("txtId"); //TextBox t2=(TextBox )GridView1.Rows[e.RowIndex ].FindControl ("txtName"); GridViewRow row = GridView1.Rows[e.RowIndex]; TextBox t = (TextBox)row.FindControl("txtId"); TextBox t2 = (TextBox)row.FindControl("txtName"); con.Open(); cmd = new OdbcCommand("update table AdminAddNewItem set Node_Name= '" + t2.Text + "' where Node_Id=" + t.Text, con); cmd.ExecuteNonQuery(); con.Close();
-
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { //TextBox t= (TextBox )GridView1.Rows[e.RowIndex ].FindControl ("txtId"); //TextBox t2=(TextBox )GridView1.Rows[e.RowIndex ].FindControl ("txtName"); GridViewRow row = GridView1.Rows[e.RowIndex]; TextBox t = (TextBox)row.FindControl("txtId"); TextBox t2 = (TextBox)row.FindControl("txtName"); con.Open(); cmd = new OdbcCommand("update table AdminAddNewItem set Node_Name= '" + t2.Text + "' where Node_Id=" + t.Text, con); cmd.ExecuteNonQuery(); con.Close();
Apart from the part where your code is broken and I can erase your entire database with it ? What's happening with this code ? Why do you feel it needs correcting ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { //TextBox t= (TextBox )GridView1.Rows[e.RowIndex ].FindControl ("txtId"); //TextBox t2=(TextBox )GridView1.Rows[e.RowIndex ].FindControl ("txtName"); GridViewRow row = GridView1.Rows[e.RowIndex]; TextBox t = (TextBox)row.FindControl("txtId"); TextBox t2 = (TextBox)row.FindControl("txtName"); con.Open(); cmd = new OdbcCommand("update table AdminAddNewItem set Node_Name= '" + t2.Text + "' where Node_Id=" + t.Text, con); cmd.ExecuteNonQuery(); con.Close();
Use stored procedure...or atleast use parametrised Query , Please don't write like this
-
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { //TextBox t= (TextBox )GridView1.Rows[e.RowIndex ].FindControl ("txtId"); //TextBox t2=(TextBox )GridView1.Rows[e.RowIndex ].FindControl ("txtName"); GridViewRow row = GridView1.Rows[e.RowIndex]; TextBox t = (TextBox)row.FindControl("txtId"); TextBox t2 = (TextBox)row.FindControl("txtName"); con.Open(); cmd = new OdbcCommand("update table AdminAddNewItem set Node_Name= '" + t2.Text + "' where Node_Id=" + t.Text, con); cmd.ExecuteNonQuery(); con.Close();
Hi, Please use the following line to access the data grid textbox value from code behind Convert.ToString(CType(GridView1.Rows(i).FindControl("Text1"), Textbox).Text) Thanks, Raja.S
-
Apart from the part where your code is broken and I can erase your entire database with it ? What's happening with this code ? Why do you feel it needs correcting ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.