473,699 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Events firing order in .NET application, help needed!

I've made an .NET application where the contents of a datagrid (dgr1)
is changed when the user changes the selection in a drop-down list
(drd1). This has works fine as a beginning.
Then I want to manipulate the look of the datagrid.
I do this in the ItemCreated event, and on the first run (application
start) this works as supposed. But when a selection is made in drd1, I
find during debugging that the dgr1_ItemCreate d event is fired before
the drd1_SelectedIn dexChanged. Since the update of the dataset is
performed in the SelectedIndexCh anged event, this results in an error.
Why are the events fired in this order? To me it seems obvious that
the SelectedIndexCh anged event should be fired first, or???

This is parts of my code showing the two events:

Private Sub Dgr1_ItemCreate d(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
Dgr1.ItemCreate d

Dim MyObj As Object

If e.Item.ItemType = ListItemType.He ader Then
e.Item.Font.Ita lic = True
e.Item.Font.Bol d = True
End If

If Not ((e.Item.ItemTy pe.ToString() = "Header") Or
(e.Item.ItemTyp e.ToString() = "Footer")) Then
MyObj = CType(e.Item.Da taItem, Object)
' Dummy declared at page level
If Dummy <> MyObj.row.itema rray(0) Then
Dummy = MyObj.row.itema rray(0)
Else
e.Item.Visible = False

End If
End If
End Sub

Private Sub drd1_SelectedIn dexChanged(ByVa l sender As System.Object,
ByVal e As System.EventArg s) Handles cmbCategory.Sel ectedIndexChang ed

'Update parameter
SqlDataAdapter1 .SelectCommand. Parameters(1).V alue =
drd1.SelectedIt em.Value
'Update Dataset1
DataSet1.Clear( )
SqlDataAdapter1 .Fill(DataSet1)
Drg1.DataBind()

End sub
Any suggestions how to fix this?
Regards,

John Martin
Nov 17 '05 #1
1 1616
Well...no. :-)

ItemCreated is called whenever DataGridItem is created, that happens when
grid is databound (items created based on datasource) and when DataGrid is
restored from ViewState (happens at LoadViewState phase before Page_Load).
It means ItemCreated event can even be raised more than once during a
request (grid is restored from ViewState and again rebound based on certain
action when it happensd twice).

ItemDataBound again is raised only when DataGrid is databound, that is,
DataBind() is called.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"John Martin" <jm*@larvikbank en.no> wrote in message
news:f8******** *************** ***@posting.goo gle.com...
I've made an .NET application where the contents of a datagrid (dgr1)
is changed when the user changes the selection in a drop-down list
(drd1). This has works fine as a beginning.
Then I want to manipulate the look of the datagrid.
I do this in the ItemCreated event, and on the first run (application
start) this works as supposed. But when a selection is made in drd1, I
find during debugging that the dgr1_ItemCreate d event is fired before
the drd1_SelectedIn dexChanged. Since the update of the dataset is
performed in the SelectedIndexCh anged event, this results in an error.
Why are the events fired in this order? To me it seems obvious that
the SelectedIndexCh anged event should be fired first, or???

This is parts of my code showing the two events:

Private Sub Dgr1_ItemCreate d(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
Dgr1.ItemCreate d

Dim MyObj As Object

If e.Item.ItemType = ListItemType.He ader Then
e.Item.Font.Ita lic = True
e.Item.Font.Bol d = True
End If

If Not ((e.Item.ItemTy pe.ToString() = "Header") Or
(e.Item.ItemTyp e.ToString() = "Footer")) Then
MyObj = CType(e.Item.Da taItem, Object)
' Dummy declared at page level
If Dummy <> MyObj.row.itema rray(0) Then
Dummy = MyObj.row.itema rray(0)
Else
e.Item.Visible = False

End If
End If
End Sub

Private Sub drd1_SelectedIn dexChanged(ByVa l sender As System.Object,
ByVal e As System.EventArg s) Handles cmbCategory.Sel ectedIndexChang ed

'Update parameter
SqlDataAdapter1 .SelectCommand. Parameters(1).V alue =
drd1.SelectedIt em.Value
'Update Dataset1
DataSet1.Clear( )
SqlDataAdapter1 .Fill(DataSet1)
Drg1.DataBind()

End sub
Any suggestions how to fix this?
Regards,

John Martin

Nov 17 '05 #2

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

Similar topics

2
1070
by: AC | last post by:
I have a page where I'm displaying articles based on the current year selected. My page dynamically builds a few links at the top to select a different year than the current one selected (the current year is not shown as an option). Then, based on the year selected, I am performing some specific logic to display the articles. By default, the first time the page loads, I default to the current year. Within my Page_Load, I have the...
1
7580
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
5
11789
by: Ben Fidge | last post by:
I've got a problem where some buttons placed on a user control are only firing their OnClick events when the user clicks on them for the second time. I've got the situation where some common functionality (Insert/Edit/Save/Cancel) is wrapped up in a user control. This control is embedded on several other user controls. I don't know if this is relevant or not but the latter
9
2304
by: Erik Frey | last post by:
Hi there, Just curious as to whether there's a clever way to see the events a control/object is firing off, perhaps written out to the debug console. It would be really handy to know which events a control is firing when I perform a certain action, and the order in which they are occurring. Thanks, Erik
7
23080
by: Scott Emick | last post by:
How can I disable events for the controls on a form? I tried setting the form's enable property to false, but that doesn't stop events from firing on its controls. I need to temporarily disable a form and load values into controls without any events firing, then re-enable the form. -- Scott Emick Web Programmer
8
2630
by: Frank van Vugt | last post by:
Hi, If during a transaction a number of deferred triggers are fired, what will be their execution order upon the commit? Will they be executed in order of firing or alfabetically or something entirely different? The docs only mention regular triggers being executed alfabetically.
5
1767
by: Paal Berggreen | last post by:
I am involved with development of a Portal solution using ASP.NET 2.0 and WebParts. The WebParts framework use the default personalization providers, and the personalization data thus ends up in the aspnetdb database (which we have placed on a proper SQL Server, not SQL Server Express). Everything works like a charm, with the following exception: New users in the system have to press links or buttons twice upon their first logon to...
6
2267
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to the same method (aka delegate?). I use the Tag property within this method to determine what user action is taking place. Very simple: When adding toolbar button: tbButton.Click += new...
5
2771
by: Daniel | last post by:
Hey guys When you hook an event (c# 2.0 syntax): myEvent += MyMethodToFire; You need to also unsubscribe it to avoid a resource leak so that the object it is in gets garbage collected like so : myEvent -= MyMethodToFire; That's all fine, but when you use visual studio to create events for objects it never creates an unsubscribing reference, so is it puting in resource leaks? Or is this being cleared somewhere that i am not seeing?
0
8615
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9173
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
8911
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
8882
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7748
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...
1
6533
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4375
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...
1
3057
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
3
2009
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.