Event Fire in Drop Down List
-
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.
-
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.
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
-
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
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.
-
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.
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
-
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
AutoPostBack property is True.
-
AutoPostBack property is True.
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 :)