By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,143 Members | 1,854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,143 IT Pros & Developers. It's quick & easy.

ItemDataBound doesn't fire when I use DeleteCommand

P: n/a
Hello:

I'm deleteing data using Datagrid, then rebind it. For some reason
ItemDataBound event doesn't fire after DeleteCommand. Why is this? Is it by
design, or I'm missing something? I have some important calculations in
ItemDataBound event. My code for DeleteCommand is below.

I would appreciate your help very much.

Private Sub dgData_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgData.DeleteCommand
Dim lbl As Label
Dim nID As String
Dim dv As DataView
Try
lbl = CType(e.Item.FindControl("lblID"), Label)
nID = CInt(lbl.Text)
oCnn.ConnectionString = smi_class.Constants.Wip7bConnectionString
oCnn.Open()
With oCmd
..Connection = oCnn
..CommandType = CommandType.StoredProcedure
..CommandText = "dbo.uspDeletePressOrder"
End With
With oCmd.Parameters
..Add("@ID", SqlDbType.Int).Direction = ParameterDirection.Input
..Item("@ID").Value = nID
End With
oCmd.ExecuteNonQuery()

If Not IsNothing(Session("DV")) Then
dv = CType(Session("DV"), DataView)
dv.RowFilter = "ID = " & nID
If dv.Count > 0 Then
dv(0).Delete()
End If
dv.RowFilter = String.Empty
Session("DV") = dv
If dv.Count > 0 Then
Me.dgData.DataSource = dv
Me.dgData.DataBind()
Else
Me.dgData.Visible = False
End If
Else
BindGrid()
End If
dgData.EditItemIndex = -1
CalculateTotals()
Catch ex As Exception
Me.lblError.Text = "Error No.: " & Err.Number.ToString & " - " & ex.ToString
Finally
If Not IsNothing(oCmd) Then
oCmd.Dispose()
End If
If Not IsNothing(cnn) Then
If cnn.State = ConnectionState.Open Then
cnn.Close()
End If
End If
End Try
End Sub

Thank you,

--
Peter Afonin

Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
By default, when ever one of the DataGrid's events are called
(DeleteCommand, EditCommand, etc), you have to rebind your grid at the end
of the event handler. Try rebinding your data before you leave the
DeleteCommand method.

HTH,
Bill P.
"Peter Afonin" <pa**@specialtypulltabs.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello:

I'm deleteing data using Datagrid, then rebind it. For some reason
ItemDataBound event doesn't fire after DeleteCommand. Why is this? Is it by design, or I'm missing something? I have some important calculations in
ItemDataBound event. My code for DeleteCommand is below.

I would appreciate your help very much.

Private Sub dgData_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgData.DeleteCommand
Dim lbl As Label
Dim nID As String
Dim dv As DataView
Try
lbl = CType(e.Item.FindControl("lblID"), Label)
nID = CInt(lbl.Text)
oCnn.ConnectionString = smi_class.Constants.Wip7bConnectionString
oCnn.Open()
With oCmd
.Connection = oCnn
.CommandType = CommandType.StoredProcedure
.CommandText = "dbo.uspDeletePressOrder"
End With
With oCmd.Parameters
.Add("@ID", SqlDbType.Int).Direction = ParameterDirection.Input
.Item("@ID").Value = nID
End With
oCmd.ExecuteNonQuery()

If Not IsNothing(Session("DV")) Then
dv = CType(Session("DV"), DataView)
dv.RowFilter = "ID = " & nID
If dv.Count > 0 Then
dv(0).Delete()
End If
dv.RowFilter = String.Empty
Session("DV") = dv
If dv.Count > 0 Then
Me.dgData.DataSource = dv
Me.dgData.DataBind()
Else
Me.dgData.Visible = False
End If
Else
BindGrid()
End If
dgData.EditItemIndex = -1
CalculateTotals()
Catch ex As Exception
Me.lblError.Text = "Error No.: " & Err.Number.ToString & " - " & ex.ToString Finally
If Not IsNothing(oCmd) Then
oCmd.Dispose()
End If
If Not IsNothing(cnn) Then
If cnn.State = ConnectionState.Open Then
cnn.Close()
End If
End If
End Try
End Sub

Thank you,

--
Peter Afonin

Nov 18 '05 #2

P: n/a
Thank you.

I'm doing it!

If..............................
.................................
If dv.Count > 0 Then
Me.dgData.DataSource = dv
Me.dgData.DataBind()
Else
Me.dgData.Visible = False
End If
Else
BindGrid()
End If

Peter

"Bill Priess" <no*****@nospam.com> wrote in message
news:ur**************@TK2MSFTNGP10.phx.gbl...
By default, when ever one of the DataGrid's events are called
(DeleteCommand, EditCommand, etc), you have to rebind your grid at the end
of the event handler. Try rebinding your data before you leave the
DeleteCommand method.

HTH,
Bill P.
"Peter Afonin" <pa**@specialtypulltabs.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello:

I'm deleteing data using Datagrid, then rebind it. For some reason
ItemDataBound event doesn't fire after DeleteCommand. Why is this? Is it

by
design, or I'm missing something? I have some important calculations in
ItemDataBound event. My code for DeleteCommand is below.

I would appreciate your help very much.

Private Sub dgData_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgData.DeleteCommand
Dim lbl As Label
Dim nID As String
Dim dv As DataView
Try
lbl = CType(e.Item.FindControl("lblID"), Label)
nID = CInt(lbl.Text)
oCnn.ConnectionString = smi_class.Constants.Wip7bConnectionString
oCnn.Open()
With oCmd
.Connection = oCnn
.CommandType = CommandType.StoredProcedure
.CommandText = "dbo.uspDeletePressOrder"
End With
With oCmd.Parameters
.Add("@ID", SqlDbType.Int).Direction = ParameterDirection.Input
.Item("@ID").Value = nID
End With
oCmd.ExecuteNonQuery()

If Not IsNothing(Session("DV")) Then
dv = CType(Session("DV"), DataView)
dv.RowFilter = "ID = " & nID
If dv.Count > 0 Then
dv(0).Delete()
End If
dv.RowFilter = String.Empty
Session("DV") = dv
If dv.Count > 0 Then
Me.dgData.DataSource = dv
Me.dgData.DataBind()
Else
Me.dgData.Visible = False
End If
Else
BindGrid()
End If
dgData.EditItemIndex = -1
CalculateTotals()
Catch ex As Exception
Me.lblError.Text = "Error No.: " & Err.Number.ToString & " - " &

ex.ToString
Finally
If Not IsNothing(oCmd) Then
oCmd.Dispose()
End If
If Not IsNothing(cnn) Then
If cnn.State = ConnectionState.Open Then
cnn.Close()
End If
End If
End Try
End Sub

Thank you,

--
Peter Afonin


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.