473,666 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_ItemDat aBound(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
dtgTest.ItemDat aBound
Dim itemType As ListItemType = e.Item.ItemType
Dim btnEdit As New Button

If ((itemType = ListItemType.Pa ger) Or (itemType =
ListItemType.He ader) Or (itemType = ListItemType.Fo oter)) Then
Return
Else
btnEdit.Style.I tem("BACKGROUND-IMAGE") =
"url(http://localhost/Images/Edit.gif)"
btnEdit.Style.I tem("BACKGROUND-REPEAT") = "no-repeat"
btnEdit.Width = Unit.Pixel(23)
btnEdit.ID = "btnEdit" & e.Item.DataSetI ndex

AddHandler btnEditar.Click , AddressOf Edit

e.Item.Cells(4) .Controls.Add(b tnEdit)
End If
End Sub

Private Sub Edit(ByVal sender As System.Object, ByVal e As
System.EventArg s)
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(strIDBu tton, Len("btnEdit") + 1,
Len(strIDButton )))

dtgTest.EditIte mIndex = index

dtgTest.DataSou rce = Session("_DataV iew")
dtgTest.DataBin d()

'I try to remove its event handlers before removing the button,
but id doesn't work either
RemoveHandler CType(dtgTest.I tems(index).Cel ls(4).Controls( 0),
Button).Click, AddressOf Edit

dtgTest.Items(i ndex).Cells(4). Controls.Remove At(0)

btnSave.Style.I tem("BACKGROUND-IMAGE") =
"url(http://localhost/Images/Save.gif)"
btnSave.Style.I tem("BACKGROUND-REPEAT") = "no-repeat"
btnSave.Width = Unit.Pixel(23)
btnSave.ID = "btnSave" & index

AddHandler btnSave.Click, AddressOf Save

dtgTest.Items(i ndex).Cells(4). Controls.Add(bt nSave)

btnCancel.Style .Item("BACKGROU ND-IMAGE") =
"url(http://localhost/Images/Cancel.gif)"
btnCancel.Style .Item("BACKGROU ND-REPEAT") = "no-repeat"
btnCancel.Width = Unit.Pixel(23)
btnCancel.ID = "btnCancel" & index

AddHandler btnCancel.Click , AddressOf Cancel

dtgTest.Items(i ndex).Cells(4). Controls.Add(bt nCancel)
End Sub
' This events are not called... why????
Private Sub Cancell(ByVal sender As System.Object, ByVal e As
System.EventArg s)

End Sub

Private Sub Guardar(ByVal sender As System.Object, ByVal e As
System.EventArg s)

End Sub

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

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

Similar topics

3
9218
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 click on a row (withs will turn blue then) and then click on it again . Now if I press any key the event will fire (except for the arrow keys). I also tried to override the IsInputKey => no luck. I also tried to override the ProcessCmdKey => With...
2
2382
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 to think how does .Net do it if I turn the viewstat on. If you use the Request.Form then you can get all the controls tha
0
1441
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 adds a handler to the click event. When a button is clicked, the background-color is set to blue.
2
1215
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 to get my new buttons to fire their events. http://www.adquiesco.com/ShowCollection.aspx?collection=4 As far as I can tell the problem has something to do with the point in the page execution where events are wired up.
1
1755
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. Any ideas? My Code : private void InitializeComponent()
0
2991
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 implement those buttons, but I'm not sure what the code should look like. I tried what I thought was obvious code: myCollection.AddNew() and
0
244
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 buttons doesn't fire his events... what I'm doing wrong? Thanks!
3
8267
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 outside the data. The trouble is, the underlying cells or columns or whatever would like to have something to say about this. The cells respond to the DoubleClick but not the grid. How do I get my event handler to handle all double clicks...
0
1664
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 process the selected rows. The problem is that the KEY events don't seem to be firing on the datagrid. When I just click on a column of the datagrid, and then press a key, the events fire. However, when I use the above keys and select some rows,...
0
8871
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8552
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.