Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to invoke onbubbleevent in datagrid

How to invoke onbubbleevent in datagrid

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    atul_moghe
    wrote on last edited by
    #1

    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.

    M 1 Reply Last reply
    0
    • A atul_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.

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      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 the OnBubbleEvent method. If you simply override the OnBubbleEvent method of the datagrid, it still won't work since the dropdownlist is contained in a DataGridItem object which represents for an item of the grid. Also, as you create a custom DataGridItem class, you are required to override the CreateControlHierarchy 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 the OnSelectedIndexChanged method, and call the RaiseBubbleEvent 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 the DataGridItem only bubbles the event which has the event data of the CommandEventArgs 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.

      S 1 Reply Last reply
      0
      • M minhpc_bk

        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 the OnBubbleEvent method. If you simply override the OnBubbleEvent method of the datagrid, it still won't work since the dropdownlist is contained in a DataGridItem object which represents for an item of the grid. Also, as you create a custom DataGridItem class, you are required to override the CreateControlHierarchy 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 the OnSelectedIndexChanged method, and call the RaiseBubbleEvent 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 the DataGridItem only bubbles the event which has the event data of the CommandEventArgs 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.

        S Offline
        S Offline
        Shawn_H
        wrote on last edited by
        #3

        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

        M 2 Replies Last reply
        0
        • S Shawn_H

          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

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          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[^]

          1 Reply Last reply
          0
          • S Shawn_H

            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

            M Offline
            M Offline
            minhpc_bk
            wrote on last edited by
            #5

            One more thing, as you migrate from classic ASP and ColdFusion, so I think you might want to check out some guide here: Migrating from other Web Technologies[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups