datagrid delete problem

Results 1 to 2 of 2

Thread: datagrid delete problem

  1. #1
    Join Date
    Dec 1969

    Default datagrid delete problem

    I&#039;ve added a delete button and code to delete individual items from a datagrid. When I click on the button the pages flickers but the item is not deleted. Any ideas?<BR><BR>Heres my code:<BR><BR> Public Sub miDataGrid_Delete(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs )<BR><BR> Dim dbCommand As SqlClient.SqlCommand<BR> Dim dbConnection As SqlClient.SqlConnection<BR> Dim strSQL As String<BR> Dim intTempid As Integer<BR><BR> intTempid = e.Item.Cells(2).Text()<BR><BR> dbConnection = New SqlClient.SqlConnection()<BR> dbConnection.ConnectionString = ConfigurationSettings.AppSettings("ConString")<BR> <BR> strSQL = "Delete * from tblMPC7a_Grid where MPC07a_ID = " & intTempid<BR><BR> dbCommand = New SqlClient.SqlCommand(strSQL, dbConnection)<BR> dbCommand.CommandType = CommandType.Text<BR><BR> dbConnection.Open()<BR><BR> Try<BR> dbCommand.ExecuteNonQuery()<BR><BR> Catch Exp As SqlClient.SqlException<BR><BR> Finally<BR> dbConnection.Close()<BR> End Try<BR><BR> Call FillmiDataGrid()<BR><BR> End Sub<BR> &#039;04/06/2004 - new delete item from grid option<BR><BR><BR>thanks<BR><BR>Lee<BR>

  2. #2
    Join Date
    Dec 1969

    Default trace your code!

    Right after the line<BR>[code language="VB.NET"]intTempid = e.Item.Cells(2).Text()[/code]<BR><BR>make sure that it pulled a value by seeing if that variable got filled by setting "trace=true" at the top of the aspx page and then right after the above line<BR>[code language="VB.NET"]Trace.Warn("TempID",intTempid)[/code]<BR><BR>also i noticed the way you are pulling the ID, much better and more predicable way of doing something like that is ot use the &#060;asp:DataGrid&#062;&#039;s "DataKeyField" parameter set to the column name of the data&#039;s Promary Key, then in code you simply say<BR><BR>[code language="VB.NET"]DataGridID.DataKeys(e.Item.ItemIndex)[/code]<BR><BR>Where "DataGridID" = your DataGrid&#039;s name

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts