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 2 1966
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mark |
last post by:
Not sure this is the right place for this questions, but here goes:
I get an error message when deleting an table from a Access database.
The code is as follows and the error message is after...
|
by: kscdavefl |
last post by:
When I execute the following code:
private void applicationPermissionGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType ==...
|
by: James G. Beldock |
last post by:
Has anyone else had the following problem: place a DataGrid within an
ASP.Net table cell and suddenly none of the ItemDataBound events seem to
fire. Move it back out and they fire just fine....
...
|
by: Steve Klett |
last post by:
Hi-
I am developing a hierarchical navigation system. I have a DataList with
the root level items, on the ItemDataBound event, I check for the selected
item, when found I'm adding an additional...
|
by: Ofer |
last post by:
I finally learned that
DataGrid1.EditItemIndex = {row I want} -1
DataGrid1.DataBind()
will make that row get to edit mode.
I am stiil looking for ways to programticaly do other things:
1) show...
|
by: Girish |
last post by:
Im trying to create a grid within a grid programmatically. Ive been
successful in doing this but I need the embedded grid to fire its
ItemDataBound event so I can handle it. The event does not seem...
|
by: Jim Andersen |
last post by:
Just to let you know, and to help any future sorry sods who gets trapped in
the same black hole......
You can't just copy/move a working sql-statement into a stored procedure.
Working with a...
|
by: greenb |
last post by:
I'm using the ItemDataBound event of the DataGrid to highlight cells that are
outside an acceptable range. Each row has a button column
(CommandName='Select'), that is used to display addtional...
|
by: SAL |
last post by:
Hello,
I created a datagrid where I set the Events to there associated functions
(i.e. Grid1_UpdateCommand, etc.). All these Events I have established work
as they are suppose to except for my...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |