473,566 Members | 3,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDownList Postback clears the selected value

MU
Hello

I have a form with a dropdownlist on it and in the page_load I have
this to populate it:
Dim productsAdapter As New ProductsTableAd apter
drpProducts.Dat aSource = productsAdapter .GetProducts()
drpProducts.Dat aTextField = "Title"
drpProducts.Dat aValueField = "ProductID"
drpProducts.Dat aBind()

Here is the drop down list:
<asp:DropDownLi st ID="drpProducts " runat="server"
AutoPostBack="T rue" class="textbox" >
</asp:DropDownLis t>

It populates with the correct fields etc but when the postback
happens, it refreshes the list and goes back to the 1st item in the
list, it doesn't maintain view state. IE. if I choose the 3rd in the
list, it doesn't refresh the page back and select the 3rd in the list
again, I'm assuming it's because of the code in the page_load.

How do I make it stay on the selected list item as I will be using it
with a gridview below it to edit records.

Thanks
MU
Oct 23 '08 #1
3 12846
MU wrote:
Hello

I have a form with a dropdownlist on it and in the page_load I have
this to populate it:
Dim productsAdapter As New ProductsTableAd apter
drpProducts.Dat aSource = productsAdapter .GetProducts()
drpProducts.Dat aTextField = "Title"
drpProducts.Dat aValueField = "ProductID"
drpProducts.Dat aBind()

Here is the drop down list:
<asp:DropDownLi st ID="drpProducts " runat="server"
AutoPostBack="T rue" class="textbox" >
</asp:DropDownLis t>

It populates with the correct fields etc but when the postback
happens, it refreshes the list and goes back to the 1st item in the
list, it doesn't maintain view state. IE. if I choose the 3rd in the
list, it doesn't refresh the page back and select the 3rd in the list
again, I'm assuming it's because of the code in the page_load.

How do I make it stay on the selected list item as I will be using it
with a gridview below it to edit records.

Thanks
MU
I should say see the above post and reply but you need to put an
IsPostBack in your form load or you will overwrite the state of the
postback every time.

LS
Oct 23 '08 #2
I sometimes have trouble with this as well, but I think it is usually better
to do the populating in the Page_Init event. ViewState is not loaded during
the Init event, so you won't be overwriting it. I make no promises, since I
am not an expert on ViewState/PostBack problems, but see if this makes any
difference. Good Luck!
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"MU" <mi*****@lonely programmer.comw rote in message
news:c2******** *************** ***********@m32 g2000hsf.google groups.com...
Hello

I have a form with a dropdownlist on it and in the page_load I have
this to populate it:
Dim productsAdapter As New ProductsTableAd apter
drpProducts.Dat aSource = productsAdapter .GetProducts()
drpProducts.Dat aTextField = "Title"
drpProducts.Dat aValueField = "ProductID"
drpProducts.Dat aBind()

Here is the drop down list:
<asp:DropDownLi st ID="drpProducts " runat="server"
AutoPostBack="T rue" class="textbox" >
</asp:DropDownLis t>

It populates with the correct fields etc but when the postback
happens, it refreshes the list and goes back to the 1st item in the
list, it doesn't maintain view state. IE. if I choose the 3rd in the
list, it doesn't refresh the page back and select the 3rd in the list
again, I'm assuming it's because of the code in the page_load.

How do I make it stay on the selected list item as I will be using it
with a gridview below it to edit records.

Thanks
MU

Oct 24 '08 #3
Nathan Sokalski wrote:
I sometimes have trouble with this as well, but I think it is usually better
to do the populating in the Page_Init event. ViewState is not loaded during
the Init event, so you won't be overwriting it. I make no promises, since I
am not an expert on ViewState/PostBack problems, but see if this makes any
difference. Good Luck!
Nathan you only want to populate the form once. That is when the form
is loaded (the first time). The way to test is the IsPostBack. You do
not need to load twice.

LS
Oct 24 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6998
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone changes box1, I want to set the selected index in box2 = 0. When I do this, I dont get an error, but when the page loads, it still has the selected...
5
1668
by: tshad | last post by:
Here is the DropDown: <asp:DropDownList ID="ScreenTest" runat="server" /> Here is the code: ScreenTest.DataSource=objCmd.ExecuteReader ScreenTest.DataValueField="ScreenTemplateMasterID" ScreenTest.DataTextField= "ScreenName" ScreenTest.databind() ScreenTest.Items.Insert(0, new ListItem("Select Screen Test",0))
10
6359
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code: dropdownlist.items.findbyvalue("value").selected = true I didnt specify any selected item in the dropdownlist during binding to the datasource. I use dropdownlist.clearselection() but...
4
6122
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the extra item just doesn't get added to the DropDownList: ============================================= <script runat="server"> Sub...
3
10566
by: Lohboy | last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET side.) I have two DropDownList controls the second of which resides within an UpdatePanel control which responds to a change in the first DropDownList. I also have a hidden button nested inside the...
18
5416
by: Redhairs | last post by:
Is it possible to get DropDownList.SelectedValue in Page_PreInit() event during the postback?
1
4645
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by pressing Remove button the selecetd row will be...
0
3480
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row...
1
4915
by: Brett | last post by:
I have a DropDownList in an ASP.NET web form that is populated with items from a lookup table by binding that DropDownList to a SqlDataSource. However, the items in the lookup table can change over time. The problem is that when an item has been removed from the lookup table, and a user wants to retrieve a record that used the deleted item,...
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.