Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > ItemDataBound doesn't fire when I use DeleteCommand

Reply
Thread Tools

ItemDataBound doesn't fire when I use DeleteCommand

 
 
Peter Afonin
Guest
Posts: n/a
 
      11-19-2003
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



 
Reply With Quote
 
 
 
 
Bill Priess
Guest
Posts: n/a
 
      11-19-2003
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" <> wrote in message
news:%...
> 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
>
>
>



 
Reply With Quote
 
 
 
 
Peter Afonin
Guest
Posts: n/a
 
      11-19-2003
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" <> wrote in message
news:...
> 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" <> wrote in message
> news:%...
> > 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
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataList.DeleteCommand event is not getting fired Nathan Sokalski ASP .Net 4 05-21-2006 05:17 PM
ItemDataBound event does not fire for selected row. =?Utf-8?B?Z3JlZW5i?= ASP .Net 1 04-24-2006 04:04 PM
When I click the cancel button of the DataGrid control, it raises DeleteCommand event!!! Why???????? XueWu ASP .Net 0 07-12-2005 01:42 PM
ItemDataBound doesn't fire when I use DeleteCommand Peter Afonin ASP .Net 2 11-19-2003 05:26 PM
ItemDataBound doesn't fire when I use DeleteCommand Peter Afonin ASP .Net Datagrid Control 0 11-19-2003 12:34 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57