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 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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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))
|
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...
|
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...
|
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...
| |
by: Redhairs |
last post by:
Is it possible to get DropDownList.SelectedValue in Page_PreInit() event
during the postback?
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |