473,320 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Dropdownlist.SelectedValue ISSUE

Hi,
I have a dropdownlist, which I am creating during runtime. I am then
populating it dynamically. Depeding on a condition, I am changing the
selected value. After this I am adding the dropdown to a panel. But
the dropdown is not showing the new selected value when the page
loads. Does anyone had similar problems? Any help is greatly
appreciated.

Thanks,
Sudhir
Nov 18 '05 #1
2 5799
> I have a dropdownlist, which I am creating during runtime. I am then
populating it dynamically. Depeding on a condition, I am changing the
selected value. After this I am adding the dropdown to a panel. But
the dropdown is not showing the new selected value when the page
loads. Does anyone had similar problems? Any help is greatly
appreciated.

Sudhir, try doing something like:

Dim lb as ListItem = myDDL.Items.FindByValue(value to look for)
If Not lb Is Nothing Then lb.Selected = True
See if that doesn't do the trick... :-)

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!


Nov 18 '05 #2
Im having what I believe to be a similar issue with the dynamic dropdownlist control and the above advice didn't help. Heres the situation: If I create a runtime asp dropdownlist and populate it with an array list, I can choose the selected value, but only the first time the page loads.

My dropdownlist is created from a function called from page load every time like so:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

poplist()

End Sub

Function poplist()

Dim k As New DropDownList
k.EnableViewState = False

'array for costcategory choices
Dim myar(2, 2)
myar(0, 0) = "1"
myar(1, 0) = "value 1"
myar(0, 1) = "2"
myar(1, 1) = "value 2"


'populate all the listitems
For i As Integer = 0 To UBound(myar, 2)
Dim myl As New ListItem
myl.Value = myar(0, i)
myl.Text = myar(1, i)
k.Items.Add(myl)
Next

Dim lb As ListItem = k.Items.FindByValue("2")
If Not lb Is Nothing Then lb.Selected = True

PlaceHolder1.Controls.Add(k)

End Function

The problem is that the selected index is only forced when the page first loads. If I have this page load, then select 'value 1' and then hit a linkbutton or anything else that triggers a postback, I would figure that the control is built again completely from scratch and 'value2' would be selected. To my dismay, 'value 1' is remembered. How could this be? My debuging follows all the seemingly logical steps including selecting the selected dropdownlist index. After postback, it just dont take. Its like my code is superceeded by something remembered. Please help.
Mar 23 '06 #3

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

Similar topics

2
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit...
1
by: I am Sam | last post by:
I have two DropDownList controls in a web form and I need to test which control has changed without wrapping it in a SelectedIndexChange Event. How do I go about this issue? I have tried the...
3
by: Ben Dewey | last post by:
Hey everyone, I have a wierd issue i can't seem to find out whats going on. I have a Control for a Shopping Cart Merchant Page called OrderStatus.ascx Inside that control there is a Repeater...
15
by: Swetha | last post by:
Hello I have a DropDownList that I am populating using the following SqlDataSource: <asp:DropDownList ID="parentIDDropDownList" runat="server" DataSourceID="SqlDataSource3"...
3
by: rengeek33 | last post by:
I have a strange issue: I have a dropdownlist (lstSrchPeriod) that has a SelectedValue of something (say "12"). I use an IF statement to determine if that value is there: If...
3
by: Carlos Lozano | last post by:
Hello, I am having a problem getting the selectedValue from a dropdownlist that is populated with a dataReader and just can't see the problem. I did the following: dim dr as DataReader dr...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
2
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
3
by: RPhlb | last post by:
This is my first post, so excuse me if I don't get this right the first time. I have an issue where when I use DropDownList I only get the first, or "SelectedValue" back when I update a GridView...
1
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.