A
Andrés Giraldo
Hi!
I'm adding an asp button to a datagrid on the ItemDataBound event, when
the user clicks on this button, I basically remove the button and create
other 2 buttons... my problem is.. the 2 last buttons doesn't fire his
events... what I'm doing wrong?
Thanks!
Private Sub dtgTest_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dtgTest.ItemDataBound
Dim itemType As ListItemType = e.Item.ItemType
Dim btnEdit As New Button
If ((itemType = ListItemType.Pager) Or (itemType =
ListItemType.Header) Or (itemType = ListItemType.Footer)) Then
Return
Else
btnEdit.Style.Item("BACKGROUND-IMAGE") =
"url(http://localhost/Images/Edit.gif)"
btnEdit.Style.Item("BACKGROUND-REPEAT") = "no-repeat"
btnEdit.Width = Unit.Pixel(23)
btnEdit.ID = "btnEdit" & e.Item.DataSetIndex
AddHandler btnEditar.Click, AddressOf Edit
e.Item.Cells(4).Controls.Add(btnEdit)
End If
End Sub
Private Sub Edit(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim strIDButton As String
Dim index As Integer
Dim btnCancel As New Button
Dim btnSave As New Button
strIDButton = CType(sender, Button).ID
index = Val(Mid(strIDButton, Len("btnEdit") + 1,
Len(strIDButton)))
dtgTest.EditItemIndex = index
dtgTest.DataSource = Session("_DataView")
dtgTest.DataBind()
'I try to remove its event handlers before removing the button,
but id doesn't work either
RemoveHandler CType(dtgTest.Items(index).Cells(4).Controls(0),
Button).Click, AddressOf Edit
dtgTest.Items(index).Cells(4).Controls.RemoveAt(0)
btnSave.Style.Item("BACKGROUND-IMAGE") =
"url(http://localhost/Images/Save.gif)"
btnSave.Style.Item("BACKGROUND-REPEAT") = "no-repeat"
btnSave.Width = Unit.Pixel(23)
btnSave.ID = "btnSave" & index
AddHandler btnSave.Click, AddressOf Save
dtgTest.Items(index).Cells(4).Controls.Add(btnSave)
btnCancel.Style.Item("BACKGROUND-IMAGE") =
"url(http://localhost/Images/Cancel.gif)"
btnCancel.Style.Item("BACKGROUND-REPEAT") = "no-repeat"
btnCancel.Width = Unit.Pixel(23)
btnCancel.ID = "btnCancel" & index
AddHandler btnCancel.Click, AddressOf Cancel
dtgTest.Items(index).Cells(4).Controls.Add(btnCancel)
End Sub
' This events are not called... why????
Private Sub Cancell(ByVal sender As System.Object, ByVal e As
System.EventArgs)
End Sub
Private Sub Guardar(ByVal sender As System.Object, ByVal e As
System.EventArgs)
End Sub
I'm adding an asp button to a datagrid on the ItemDataBound event, when
the user clicks on this button, I basically remove the button and create
other 2 buttons... my problem is.. the 2 last buttons doesn't fire his
events... what I'm doing wrong?
Thanks!
Private Sub dtgTest_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dtgTest.ItemDataBound
Dim itemType As ListItemType = e.Item.ItemType
Dim btnEdit As New Button
If ((itemType = ListItemType.Pager) Or (itemType =
ListItemType.Header) Or (itemType = ListItemType.Footer)) Then
Return
Else
btnEdit.Style.Item("BACKGROUND-IMAGE") =
"url(http://localhost/Images/Edit.gif)"
btnEdit.Style.Item("BACKGROUND-REPEAT") = "no-repeat"
btnEdit.Width = Unit.Pixel(23)
btnEdit.ID = "btnEdit" & e.Item.DataSetIndex
AddHandler btnEditar.Click, AddressOf Edit
e.Item.Cells(4).Controls.Add(btnEdit)
End If
End Sub
Private Sub Edit(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim strIDButton As String
Dim index As Integer
Dim btnCancel As New Button
Dim btnSave As New Button
strIDButton = CType(sender, Button).ID
index = Val(Mid(strIDButton, Len("btnEdit") + 1,
Len(strIDButton)))
dtgTest.EditItemIndex = index
dtgTest.DataSource = Session("_DataView")
dtgTest.DataBind()
'I try to remove its event handlers before removing the button,
but id doesn't work either
RemoveHandler CType(dtgTest.Items(index).Cells(4).Controls(0),
Button).Click, AddressOf Edit
dtgTest.Items(index).Cells(4).Controls.RemoveAt(0)
btnSave.Style.Item("BACKGROUND-IMAGE") =
"url(http://localhost/Images/Save.gif)"
btnSave.Style.Item("BACKGROUND-REPEAT") = "no-repeat"
btnSave.Width = Unit.Pixel(23)
btnSave.ID = "btnSave" & index
AddHandler btnSave.Click, AddressOf Save
dtgTest.Items(index).Cells(4).Controls.Add(btnSave)
btnCancel.Style.Item("BACKGROUND-IMAGE") =
"url(http://localhost/Images/Cancel.gif)"
btnCancel.Style.Item("BACKGROUND-REPEAT") = "no-repeat"
btnCancel.Width = Unit.Pixel(23)
btnCancel.ID = "btnCancel" & index
AddHandler btnCancel.Click, AddressOf Cancel
dtgTest.Items(index).Cells(4).Controls.Add(btnCancel)
End Sub
' This events are not called... why????
Private Sub Cancell(ByVal sender As System.Object, ByVal e As
System.EventArgs)
End Sub
Private Sub Guardar(ByVal sender As System.Object, ByVal e As
System.EventArgs)
End Sub