473,320 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Adding buttons to a datagrid doesn't fire its events

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(btnCanc el)
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #1
0 2973

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: bardo | last post by:
I have a Datagrid that is inside a panel. I want to use the keyDown event to reconize the arrow keys. But I have no luck at all. The problem is that the keydown event won't fire at all, unless I...
2
by: andla | last post by:
Hi, How does events fire in a datagrid. I know about the problem if turning the viewstate off the events wil not fire properly even if I rebind the control in every postback. S then I started...
0
by: Klaus Jensen | last post by:
Hi! This has been annoying me for a while now, and I can't get it to work It is really driving me nuts! Basicly this simple webapp created to illustrate my problem, renders five buttons, and...
2
by: Oddball | last post by:
I am trying to create and add a number of ImageButtons to a page when a certain event is called. Not only am I suffering from my page running the "Page_Load" event three times, but I can't seem...
1
by: John Hughes | last post by:
Im adding a button at runtime to a datagrid but the DataGrid1.ItemCommand event does not fire. I also have a button that I added at design time and this button does fire the event ItemCommand. ...
0
by: Adam J. Schaff | last post by:
Hello. I have a custom collection that implements IBindingList (allownew and allowremove are both true). I have bound it to a datagrid. I have add and remove buttons on the screen. I want to...
0
by: Andrés Giraldo | last post by:
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...
3
by: C Glenn | last post by:
I would like one DoubleClick event handler to handle all double clicks throughout a DataGrid. I've assigned a DoubleClick event handler to the DataGrid and it works nifty-spiffy so long as I click...
0
by: WhiteWizard | last post by:
I am trying to implement standard multi-select of rows in a datagrid. That is, allow the user to use the CTRL & SHIFT keys to select multiple rows in a datagrid. Then I'll loop through them and...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.