ItemDataBound doesn't fire when I use DeleteCommand

Discussion in 'ASP .Net Web Controls' started by Peter Afonin, Nov 19, 2003.

  1. Peter Afonin

    Peter Afonin Guest

    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
     
    Peter Afonin, Nov 19, 2003
    #1
    1. Advertising

  2. Peter Afonin

    Bill Priess Guest

    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
    >
    >
    >
     
    Bill Priess, Nov 19, 2003
    #2
    1. Advertising

  3. Peter Afonin

    Peter Afonin Guest

    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
    > >
    > >
    > >

    >
    >
     
    Peter Afonin, Nov 19, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Afonin
    Replies:
    2
    Views:
    468
    Peter Afonin
    Nov 19, 2003
  2. XueWu
    Replies:
    0
    Views:
    649
    XueWu
    Jul 12, 2005
  3. =?Utf-8?B?Z3JlZW5i?=

    ItemDataBound event does not fire for selected row.

    =?Utf-8?B?Z3JlZW5i?=, Apr 24, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    2,435
    =?Utf-8?B?Z3JlZW5i?=
    Apr 24, 2006
  4. Nathan Sokalski
    Replies:
    4
    Views:
    3,563
    Nathan Sokalski
    May 21, 2006
  5. Peter Afonin

    ItemDataBound doesn't fire when I use DeleteCommand

    Peter Afonin, Nov 19, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    119
    Peter Afonin
    Nov 19, 2003
Loading...

Share This Page