How to invoke onbubbleevent in datagrid
-
hi guys, I have item template in my datagrid. in tht item template i have one dropdownlist. according to the selection of tht dropdownlist i have to fill other dropdownlist and display below it. i tryied with the raisebubbleevent and onbubbleevent methods but the problem is onbubbleevent is not executing at all. can anyone help me out ?? if u can give the solution with code it would be the best thing from ur side. Thanks in advance, A R Moghe.
-
hi guys, I have item template in my datagrid. in tht item template i have one dropdownlist. according to the selection of tht dropdownlist i have to fill other dropdownlist and display below it. i tryied with the raisebubbleevent and onbubbleevent methods but the problem is onbubbleevent is not executing at all. can anyone help me out ?? if u can give the solution with code it would be the best thing from ur side. Thanks in advance, A R Moghe.
Hi there, Basically, in addition to the predefined buttons like Edit, Update, Cancel ..., only the Button/ImageButton/LinkButton controls can bubble up their click event to the datagrid control. In the meanwhile, the DropDownList does not, so if you want the dropdownlist to bubble the SelectedIndexChanged event to the datagrid, then there are a couple of options here: + Create a custom
DataGridItem
class, and override theOnBubbleEvent
method. If you simply override theOnBubbleEvent
method of the datagrid, it still won't work since the dropdownlist is contained in aDataGridItem
object which represents for an item of the grid. Also, as you create a custom DataGridItem class, you are required to override theCreateControlHierarchy
method of the datagrid. So in general, this option is quite complicated. + The easier option is to create a custom dropdownlist control which inherits from the standard dropdownlist control. In the custom control, you simply override theOnSelectedIndexChanged
method, and call theRaiseBubbleEvent
method to bubble the event to the DataGrid. The sample code looks something like:protected override void OnSelectedIndexChanged(EventArgs e)
{
base.OnSelectedIndexChanged (e);CommandEventArgs args = new CommandEventArgs("SelectedIndexChanged", EventArgs.Empty); RaiseBubbleEvent(this, args);
}
The reason you need to create an event argument of the
CommandEventArgs
type is that theDataGridItem
only bubbles the event which has the event data of theCommandEventArgs
type. + Another way is that you don't need to bubble up the event, you simply create an event handler for the SelectedIndexChanged event of the dropdownlist, and provide your logic in the handler. -
Hi there, Basically, in addition to the predefined buttons like Edit, Update, Cancel ..., only the Button/ImageButton/LinkButton controls can bubble up their click event to the datagrid control. In the meanwhile, the DropDownList does not, so if you want the dropdownlist to bubble the SelectedIndexChanged event to the datagrid, then there are a couple of options here: + Create a custom
DataGridItem
class, and override theOnBubbleEvent
method. If you simply override theOnBubbleEvent
method of the datagrid, it still won't work since the dropdownlist is contained in aDataGridItem
object which represents for an item of the grid. Also, as you create a custom DataGridItem class, you are required to override theCreateControlHierarchy
method of the datagrid. So in general, this option is quite complicated. + The easier option is to create a custom dropdownlist control which inherits from the standard dropdownlist control. In the custom control, you simply override theOnSelectedIndexChanged
method, and call theRaiseBubbleEvent
method to bubble the event to the DataGrid. The sample code looks something like:protected override void OnSelectedIndexChanged(EventArgs e)
{
base.OnSelectedIndexChanged (e);CommandEventArgs args = new CommandEventArgs("SelectedIndexChanged", EventArgs.Empty); RaiseBubbleEvent(this, args);
}
The reason you need to create an event argument of the
CommandEventArgs
type is that theDataGridItem
only bubbles the event which has the event data of theCommandEventArgs
type. + Another way is that you don't need to bubble up the event, you simply create an event handler for the SelectedIndexChanged event of the dropdownlist, and provide your logic in the handler.minhpc, Im fairly new to .NET, comming from stale old Classic ASP and Coldfusion, but I was reading your response in this thread, and just wanted clarification for myself on this '********************************* Another way is that you don't need to bubble up the event, you simply create an event handler for the SelectedIndexChanged event of the dropdownlist, and provide your logic in the handler '********************************* So if I have a dropdownListBox decared in my code behind withevents, and use the AddHandler for SelectedIndexChanged event and link it to my own custom function, will it still raise this event and call my custom function even though this control is burried in an ItemTemplate inside a datagrid? Thanks....Im learning here PS..thanks for the help in the other thread
-
minhpc, Im fairly new to .NET, comming from stale old Classic ASP and Coldfusion, but I was reading your response in this thread, and just wanted clarification for myself on this '********************************* Another way is that you don't need to bubble up the event, you simply create an event handler for the SelectedIndexChanged event of the dropdownlist, and provide your logic in the handler '********************************* So if I have a dropdownListBox decared in my code behind withevents, and use the AddHandler for SelectedIndexChanged event and link it to my own custom function, will it still raise this event and call my custom function even though this control is burried in an ItemTemplate inside a datagrid? Thanks....Im learning here PS..thanks for the help in the other thread
Shawn, Shawn_H wrote: So if I have a dropdownListBox decared in my code behind withevents, and use the AddHandler for SelectedIndexChanged event and link it to my own custom function, will it still raise this event and call my custom function even though this control is burried in an ItemTemplate inside a datagrid? Yes, but with a condition. Because, you dynamically add the dropdownlist control at runtime, you need to add it again (also re-wire up the event handler) when the page posts back since the ASP.NET does not do that for you, so you need to make sure the dynamically-added dropdownlist is in the control hierarchy when the page is visited. More importantly, the dynamic control needs to be added to the container prior to the loading of the ViewState data, otherwise the data gets lost and as a result the event of the control cannot run properly. Basically, when you work with dynamic controls, you need to be familiar with the Control Execution Lifecycle[^]
-
minhpc, Im fairly new to .NET, comming from stale old Classic ASP and Coldfusion, but I was reading your response in this thread, and just wanted clarification for myself on this '********************************* Another way is that you don't need to bubble up the event, you simply create an event handler for the SelectedIndexChanged event of the dropdownlist, and provide your logic in the handler '********************************* So if I have a dropdownListBox decared in my code behind withevents, and use the AddHandler for SelectedIndexChanged event and link it to my own custom function, will it still raise this event and call my custom function even though this control is burried in an ItemTemplate inside a datagrid? Thanks....Im learning here PS..thanks for the help in the other thread