Event Fire in Drop Down List
-
Please Everybody help me. I had been send this problem before two hour. Enter the value in dropdownlist. page_load() { dropdownlist1.items.insert(0,new listitem("Add New","0") } dropdownlist1_selectedIndexchanged() { if(dropdownlist1.selectedindex == 0) { responce.write("Asdf"); } } But not fired this event.
Here is a piece of code that works fine in my system. just check with this you are doing it right... HTML -----
<-asp:dropdownlist id="DropDownList1" runat="server" 0nSelectedIndexChanged="dropdownlist_SelectedIndexChanged" AutoPostBack="True">
Code-Behind ------------private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { DropDownList1.Items.Insert(0, new ListItem("First", "1")); DropDownList1.Items.Insert(1, new ListItem("Second", "2")); DropDownList1.Items.Insert(2, new ListItem("Third", "3")); } } public void dropdownlist_SelectedIndexChanged(object sender, System.EventArgs e) { Label1.Text = DropDownList1.SelectedItem.Text; }
Note: SelectedIndexChanged event will fire only when you change the dropdown item.Regards
- J O H N -
-
Please Everybody help me. I had been send this problem before two hour. Enter the value in dropdownlist. page_load() { dropdownlist1.items.insert(0,new listitem("Add New","0") } dropdownlist1_selectedIndexchanged() { if(dropdownlist1.selectedindex == 0) { responce.write("Asdf"); } } But not fired this event.
Please add this item as follow : dropdownlist1.items.add("abcd"); then write this code of selectedindexchanged event as follow: int index=dropdownlist1.selectedindex(); // to confirm the desired index number pls write this code Response.write(index.tostring()); if(index==0) { Response.Write("Asdf"); } Ritesh Mogha
-
Perhaps u forget two things 1.To Write the below line with in if clause having page ispostback conditon. dropdownlist1.items.insert(0,new listitem("Add New","0") and 2. set the Autopostback property of dropdownlist to True. hope it helps U. Regards Tarun Singh Sr. Software Engineer. mailto:tksingh@zenta.com
AutoPostBack Property is already true.
-
AutoPostBack Property is already true.
Gagan Deep Garg wrote:
'07 AutoPostBack Property is already true.
i didn't say anything about this :~ See that event will fire only when selected Index changed as it is in name. And by default first item is selected so it will not fire untill you select another item
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Here is a piece of code that works fine in my system. just check with this you are doing it right... HTML -----
<-asp:dropdownlist id="DropDownList1" runat="server" 0nSelectedIndexChanged="dropdownlist_SelectedIndexChanged" AutoPostBack="True">
Code-Behind ------------private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { DropDownList1.Items.Insert(0, new ListItem("First", "1")); DropDownList1.Items.Insert(1, new ListItem("Second", "2")); DropDownList1.Items.Insert(2, new ListItem("Third", "3")); } } public void dropdownlist_SelectedIndexChanged(object sender, System.EventArgs e) { Label1.Text = DropDownList1.SelectedItem.Text; }
Note: SelectedIndexChanged event will fire only when you change the dropdown item.Regards
- J O H N -
yes I check at this lines.
-
Please add this item as follow : dropdownlist1.items.add("abcd"); then write this code of selectedindexchanged event as follow: int index=dropdownlist1.selectedindex(); // to confirm the desired index number pls write this code Response.write(index.tostring()); if(index==0) { Response.Write("Asdf"); } Ritesh Mogha
No Go To My Pointer
-
yes I check at this lines.
No Go To My Pointer this function
-
No Go To My Pointer this function
-
Gagan Deep Garg wrote:
No Go To My Pointer this function
what do you mean?
Regards
- J O H N -
set the Debug pointer not go to debug pointer in this function.
-
Please Everybody help me. I had been send this problem before two hour. Enter the value in dropdownlist. page_load() { dropdownlist1.items.insert(0,new listitem("Add New","0") } dropdownlist1_selectedIndexchanged() { if(dropdownlist1.selectedindex == 0) { responce.write("Asdf"); } } But not fired this event.
set AutoPostBack to true in the DropDownList
-
set the Debug pointer not go to debug pointer in this function.