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. Event Fire in Drop Down List

Event Fire in Drop Down List

Scheduled Pinned Locked Moved ASP.NET
database
6 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.
  • R Offline
    R Offline
    Rinki Mukheraji
    wrote on last edited by
    #1

    I am using dropdownlist. this dropdown list attach in database. and dropdownlist enter the runtime value. e.g dropdownlist property: AutoPostBack= True dropdownlist1.items.insert(0,new listitem("Add new","0"); when click the Add New Then fired a event. Write a Code private void dropdownlist1_selectedIndexChange( ) { if(dropdownlist1.selectedindex == 0) { responce.wirte("asdF"); } } But this event is not fired.

    N K 2 Replies Last reply
    0
    • R Rinki Mukheraji

      I am using dropdownlist. this dropdown list attach in database. and dropdownlist enter the runtime value. e.g dropdownlist property: AutoPostBack= True dropdownlist1.items.insert(0,new listitem("Add new","0"); when click the Add New Then fired a event. Write a Code private void dropdownlist1_selectedIndexChange( ) { if(dropdownlist1.selectedindex == 0) { responce.wirte("asdF"); } } But this event is not fired.

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Gagan Deep Garg wrote:

      But this event is not fired.

      Is your page posting back ? I don't think so, I guess your drop down list contains only one item.

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

      R 1 Reply Last reply
      0
      • N N a v a n e e t h

        Gagan Deep Garg wrote:

        But this event is not fired.

        Is your page posting back ? I don't think so, I guess your drop down list contains only one item.

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

        R Offline
        R Offline
        Rinki Mukheraji
        wrote on last edited by
        #3

        One Item In Run Time.(Add New) When Click The Add New Then Appear One TextBox. Enter The Value In TextBox And Save DataBase. Then DropDown List Display Two values. One is Add New and Second is DataBase Value. My problem is: Not Fired Event.

        1 Reply Last reply
        0
        • R Rinki Mukheraji

          I am using dropdownlist. this dropdown list attach in database. and dropdownlist enter the runtime value. e.g dropdownlist property: AutoPostBack= True dropdownlist1.items.insert(0,new listitem("Add new","0"); when click the Add New Then fired a event. Write a Code private void dropdownlist1_selectedIndexChange( ) { if(dropdownlist1.selectedindex == 0) { responce.wirte("asdF"); } } But this event is not fired.

          K Offline
          K Offline
          kuyak2000
          wrote on last edited by
          #4

          Gagan Deep Garg wrote:

          dropdownlist1.items.insert(0,new listitem("Add new","0");

          If your dropdownlist only has one item, it will always choose that item. This is different with Windows Forms' ComboBox, that requires you to select first even if the ComboBox only has one item, unless you made the default selected item is the only one item available. If your dropdownlist has more than one item, any item selected will trigger PostBack (as long as AutoPostBack is set to true). Eriawan

          R 1 Reply Last reply
          0
          • K kuyak2000

            Gagan Deep Garg wrote:

            dropdownlist1.items.insert(0,new listitem("Add new","0");

            If your dropdownlist only has one item, it will always choose that item. This is different with Windows Forms' ComboBox, that requires you to select first even if the ComboBox only has one item, unless you made the default selected item is the only one item available. If your dropdownlist has more than one item, any item selected will trigger PostBack (as long as AutoPostBack is set to true). Eriawan

            R Offline
            R Offline
            Rinki Mukheraji
            wrote on last edited by
            #5

            AutoPostBack property is True.

            K 1 Reply Last reply
            0
            • R Rinki Mukheraji

              AutoPostBack property is True.

              K Offline
              K Offline
              kuyak2000
              wrote on last edited by
              #6

              Yes, I know. What I'm trying to say is, you should define items in your dropdownlist at least two items, instead of just one. Otherwise, the web browser will always chose the only one item and there will be no SelectedIndexChanged event fired, since there's just only one item. There is a historical reason for this. W3C HTML 3.2/4.0 compliant browser such as IE 4.x or above, Netscape 7 or above, Firefox 1.5/2.0 or above, and Opera 5.x or above will always treat dropdownlist to automatically select first item it found, unless it's defined by the dropdownlist. If the item is only one instead of many items, it will always select the only one item. For example, in your code you only define one item. Therefore when the ASP.NET page is rendered on client web browser, the first item selected is always the only one item and there will be no SelectedIndexChanged fired. This is the default behavior of web drop down list (or dropdownlist in ASP.NET), and there's nothing you can do to overcome this event not fired problem, since it's the default behavior. ASP.NET (even other server side Java Server Pages, Struts) itself relies on the default render behavior on web browsers. best regards, Eriawan :)

              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