private void dgLadder_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { dgLadder.EditItemIndex = (int)e.Item.ItemIndex; BindData(); } private void dgLadder_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { String updateCmd = "UPDATE Ladder SET LastName = @NLName, FirstName = @NFName, Ranking = @NRanking where Id = @SelectedId"; SqlCommand myCommand = new SqlCommand(updateCmd, connLadder); myCommand.Parameters.Add(new SqlParameter("@SelectedId",SqlDbType.NVarChar, 10)); myCommand.Parameters.Add(new SqlParameter("@NLName",SqlDbType.NVarChar, 10)); myCommand.Parameters.Add(new SqlParameter("@NFName",SqlDbType.NVarChar, 10)); myCommand.Parameters.Add(new SqlParameter("@NRanking",SqlDbType.NVarChar, 10)); myCommand.Parameters["@SelectedId"].Value = dgLadder.DataKeys[(int)e.Item.ItemIndex]; String nLName = ((TextBox)e.Item.Cells[0].Controls[0]).Text; String nFName = ((TextBox)e.Item.Cells[1].Controls[0]).Text; String nRanking = ((TextBox)e.Item.Cells[2].Controls[0]).Text; myCommand.Parameters["@NLName"].Value = nLName; myCommand.Parameters["@NFName"].Value = nFName; myCommand.Parameters["@NRanking"].Value = nRanking; myCommand.Connection.Open(); myCommand.ExecuteNonQuery(); dgLadder.EditItemIndex = -1; myCommand.Connection.Close(); BindData(); } I've tried using the following in the edit method: String oldRanking = ((TextBox)e.Item.Cells[2].Controls[0]).Text; but get error Specified argument was out of the range of valid values. Parameter name: index Can anyone help on this? Thanks
I've tried using the following in the edit method: String oldRanking = ((TextBox)e.Item.Cells[2].Controls[0]).Text; but get error Specified argument was out of the range of valid values. Parameter name: index Can anyone help on this? Thanks
String oldRanking = ((TextBox)e.Item.Cells[2].Controls[0]).Text;