GridView issue........Anyone...........please?
-
Here is the code from ASP.NET 1.1 that works. My problem is below with 2.0 GridView? private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int playerID = Convert.ToInt32(e.Item.Cells[1].Text); string sqlDelete = "delete Players where PlayerID = '" + playerID +"'"; SqlConnection conn = new SqlConnection(dsn); SqlCommand cmd = conn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = sqlDelete; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); DataGrid1.EditItemIndex = -1; BindGrid(); } This above code is ASP.NET 1.1 code for Deletion from DataGrid. It works fine. Now, I am using GridView (ASP.NET 2.0) The problem I am having is getting the playerID from GridView? ***int playerID = Convert.ToInt32(e.Item.Cells[1].Text); ** does not give any playerID but throws error? How do I get the playerID from GridView. Is the event handler Row Deleting or Row Deleted? Please help............. Sanjeev
-
Here is the code from ASP.NET 1.1 that works. My problem is below with 2.0 GridView? private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int playerID = Convert.ToInt32(e.Item.Cells[1].Text); string sqlDelete = "delete Players where PlayerID = '" + playerID +"'"; SqlConnection conn = new SqlConnection(dsn); SqlCommand cmd = conn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = sqlDelete; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); DataGrid1.EditItemIndex = -1; BindGrid(); } This above code is ASP.NET 1.1 code for Deletion from DataGrid. It works fine. Now, I am using GridView (ASP.NET 2.0) The problem I am having is getting the playerID from GridView? ***int playerID = Convert.ToInt32(e.Item.Cells[1].Text); ** does not give any playerID but throws error? How do I get the playerID from GridView. Is the event handler Row Deleting or Row Deleted? Please help............. Sanjeev
I thought you set up the DataItemIndex on the grid to be a unique ID for that row.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
I thought you set up the DataItemIndex on the grid to be a unique ID for that row.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Hi Christian, Thank you for you reply. I am sorry but I did not understand the reply...... The issue is deleting any row from the grid when gridview is shown in the page. I am trying to programmatically call the delete with code behind. Thank you, Sanjeev. Sanjeev
-
Hi Christian, Thank you for you reply. I am sorry but I did not understand the reply...... The issue is deleting any row from the grid when gridview is shown in the page. I am trying to programmatically call the delete with code behind. Thank you, Sanjeev. Sanjeev
A row on a gridview has the property I pointed out, it's purpose is to store a key that you can use to make a database call that identifies that row.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog