Last post Jul 16, 2008 01:30 PM by nideeshm
Dec 20, 2005 06:13 PM|StrongTypes|LINK
This is a very common issue that has to do with not checking for PostBack on Page_Load, which causes your DropDownList to load again on PostBack before the web form is processed. To ensure that the DropDownList gets loaded 1x
only, you will need to check for PostBack.
Private Sub Page_Load(ByVal sender
As Object, ByVal e
If Not IsPostBack Then
' Code here to bind data to DropDownList
private void Page_Load(object sender, EventArgs e)
// Code here to bind data to DropDownList
Dec 21, 2005 06:21 PM|Blake05|LINK
Dec 21, 2005 06:32 PM|StrongTypes|LINK
Dec 22, 2005 08:00 AM|PeterBrunone|LINK
Another exception is EasyListBox. No viewstate worries, no problem; you can re-bind and your selections stay intact.
Dec 24, 2005 03:22 PM|Blake05|LINK
Oct 23, 2006 01:50 PM|Amrits4eva|LINK
There is no need for the post backs, to check for the selected value in the drop down
Nov 30, 2006 11:17 AM|inrajak|LINK
are you fill the data into the dropdown list from db. if it is work fine that you can get the selected data through when it is postback(dropdownlist) or click event(). if these two not help you. let you try it useing firefox. ie some time throwing such that
Jan 16, 2007 12:17 AM|cgraving|LINK
Jan 22, 2007 11:07 AM|Dhaliwal|LINK
However, there is one exception to this. When working with dynamically created controls you need to recreate the control on PostBack. Otherwise, an exception will be thrown when you attempt to access the dynamic control in your code on PostBack.
Jan 22, 2007 04:52 PM|srinivas815|LINK
I expect that the control is fetching the data two times
1. At the time of load
2. At the time of rendering
Please try to place the entire code in the pre render event and give a try.
Feb 14, 2007 07:51 PM|Girijesh|LINK
yes you are right.
Feb 22, 2007 02:22 PM|Spidy|LINK
i think that this will work
if any problem feel free to inform
Feb 22, 2007 03:14 PM|joydipkanjilal|LINK
Bind data to the control by checking for postbacks. Refer to the code below:--
//Necessary code to bind data to the drop down list control.
Further, ensure that the view state for this control is set to true; otherwise, on a post back, it would loose the values. Then use the SelectedValue property as shown below to retrieve the user's selection..
string str = drpDownList.SelectedValue.ToString();
I blog at www.aspadvice.com/blogs/joydip
Mar 28, 2007 08:12 AM|alug|LINK
Data binding of the drop down list sould be in the in the following code.
The code of binding drop down list should go here.
and this all code should be in the Page load event.
Oct 17, 2007 08:40 PM|jesbinjoseph|LINK
How can we recreate a dropdown ?
Nov 02, 2007 08:26 PM|raskol101|LINK
I am having a simillar problem to this but it is slightly different.
I have two dropdowns the first one takes its values from SQL-SERVER database and i have it databound like so
catchanged = "56";
uxCategoryDrop.DataSource = drop;
uxCategoryDrop.DataTextField = "Name";
uxCategoryDrop.DataValueField = "CategoryID";
uxCategoryDrop.Items.FindByValue(catchanged).Selected = true;
the second dropdown pulls values from the database based on the users selection of the first.....at this point the dropdown retains the users selection.
however i then have a button which loads another control.....based on this data....it does this fine but it resets the value of the first dropdown back to the initial value....which is confusing to the user.
how do i get it to retain the user selected value after the click event?
sorry if this is obvious i am new to both asp.net and c#
Jan 25, 2008 11:58 AM|sam_soumya|LINK
yes, it is right.
Jan 26, 2008 01:47 AM|thuypv|LINK
Jan 26, 2008 07:00 AM|mathijs_bibito|LINK
You could put the the dropdownlist for the selection in a seperate UpdatePanel like:
<asp:UpdatePanel ID="UpdatePanelSelectX" runat="server" UpdateMode="Conditional">
<asp:DropdownList ID="uxCategoryDrop" runat="server">
<asp:Button ID="ButtonSearch" OnClick="ButtonSearch_Click" runat="server">BUTTON TEXT</asp:Button>
<asp:UpdatePanel ID="UpdatePanelResultX" runat="server" UpdateMode="Conditional">
protected void ButtonSearch_Click(object sender, EventArgs e)
//Bind the datasource of the data you wish to display here...
Now the dropdownlist should obtain its selected value.
If this does not work, store the Value or SelectedIndex in a ViewState and set the SelectedValue or SelectedIndex of the uxCategoryDrop to the value of the ViewState. This could be done when the PageLoad event gets triggered in a PostBack call. I would create
a private method which initializes a control which is called from the PageLoad event.
Good luck ;)
Feb 02, 2008 11:20 AM|rbansal44|LINK
write the code at the postback event in c# and after connecting it to the database with datasource ie code is
dropdownlist1.datatextfield="column1name";//name of the column in database
dropdownlist1.datavaluefield="datavalue";//name of the value field i.e id or soamething in database
this code will surely help you out.
Feb 27, 2008 04:09 AM|manganno|LINK
hi guys...i'm very new in VB.NET..really needs help...what's wrong with my coding below?pls help me...
cboorifice.DataSource = "wtestgasfmaintab" -----------> table name
cboorifice.DataTextField = "WTESTSPORIFICESZ" -----------> field name
cboorifice.DataValueField = "WTESTSPORIFICESZ" -----------> field name
Jun 06, 2008 07:39 AM|sri2705|LINK
set postback=true in dropdownlist properties
Jun 12, 2008 12:58 PM|CreativeMind|LINK
Jun 16, 2008 09:01 AM|themasterpiece83|LINK
Page.IsPostBack Gets a value indicating whether the page is being loaded in response to a client postback, or if it is being loaded and accessed for the first time. so to have value of drop down on every selection you have to check whether its PostBack or
in c#.net you can do like
private void Page_Load()
// have drop down value
// to appear before the first roundtrip.
in VB.net you can do like
Jul 16, 2008 01:30 PM|nideeshm|LINK
Declare a list item and add it to the dropdown constructively. You can use insert option of dropdown list to insert at a particular index. This becomes useful when we are binding the dropdown from database and u need a default item in dropdown