473,407 Members | 2,546 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,407 software developers and data experts.

HELP with ASP.NET DropDownList Box ! : )

Hi all,

I have a DropDownList on my page created in Design Time calledddlDate. In
code, I do the following:

1 ddlDate = New DropDownList() <- To Clear the drop down list
2 ddlDate.Items.Add("HELLO")
3 ddlDate.Items.Add("WORLD")

When the page loads, how come my drop downlist is empty? Shouldn't there be
two entries?

If I remove Line 1, then the entries are present. However, logically
speaking, why does Line 1 mess things up?

Thanks!
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 17 '05 #1
5 996
Lucas,

You say you are creating the drop down list dynamically. It sounds like you
are creating the entries in the drop down dynamically, but that the list was
added to the page in the design window.

If this is the case then the drop down you are creating (the new one) is
replacing the one in the design window and you aren't setting most of it's
attributes.

If it is the case that you have added the drop down to the page via the
design window then instead of using "New" to clear the drop down do it like
this:

ddlDate.Items.Clear()

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@207.46.248.16.. .
Hi all,

I have a DropDownList on my page created in Design Time calledddlDate. In
code, I do the following:

1 ddlDate = New DropDownList() <- To Clear the drop down list
2 ddlDate.Items.Add("HELLO")
3 ddlDate.Items.Add("WORLD")

When the page loads, how come my drop downlist is empty? Shouldn't there be two entries?

If I remove Line 1, then the entries are present. However, logically
speaking, why does Line 1 mess things up?

Thanks!
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 17 '05 #2
This has worked for me beforfe, but its IE only I think

Dim EncodedString As String = "This is a Test
String"    EndTestString"
Dim writer As New System.IO.StringWriter()
Server.HtmlDecode(EncodedString, writer)
Dim DecodedString As String = writer.ToString()
lstTest.Items.Add(DecodedString)

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
----------------------------------------------

"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@207.46.248.16.. .
Hi all,

I have a DropDownList on my page created in Design Time calledddlDate. In
code, I do the following:

1 ddlDate = New DropDownList() <- To Clear the drop down list
2 ddlDate.Items.Add("HELLO")
3 ddlDate.Items.Add("WORLD")

When the page loads, how come my drop downlist is empty? Shouldn't there be two entries?

If I remove Line 1, then the entries are present. However, logically
speaking, why does Line 1 mess things up?

Thanks!
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 17 '05 #3
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in
news:#a**************@TK2MSFTNGP12.phx.gbl:
If this is the case then the drop down you are creating (the new one)
is replacing the one in the design window and you aren't setting most
of it's attributes.
Yes exactly! That is what I am doing.

If it is the case that you have added the drop down to the page via
the design window then instead of using "New" to clear the drop down
do it like this:

ddlDate.Items.Clear()


However, shouldn't using New() to clear also work? Logically speaking,
shouldn't new() bind a new instance to the control? I wonder why it won't
pick up the newly bound control.

BTW, your suggestion worked great! Thanks for your help!

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 17 '05 #4
Lucas,

It's because other settings are defined by the page.

Take a look in the web for designer generated code area of the codebehind
page.

You'll see the following:

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

The routine above actually runs setup routines for the components on your
page. When you called "New" you overwrote all those "Hidden" settings. If
declare a new component you have to recreate them.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@207.46.248.16.. .
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in
news:#a**************@TK2MSFTNGP12.phx.gbl:
If this is the case then the drop down you are creating (the new one)
is replacing the one in the design window and you aren't setting most
of it's attributes.


Yes exactly! That is what I am doing.

If it is the case that you have added the drop down to the page via
the design window then instead of using "New" to clear the drop down
do it like this:

ddlDate.Items.Clear()


However, shouldn't using New() to clear also work? Logically speaking,
shouldn't new() bind a new instance to the control? I wonder why it won't
pick up the newly bound control.

BTW, your suggestion worked great! Thanks for your help!

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 17 '05 #5
sorry Lucas, I appear to have replied to the wrong post here

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
----------------------------------------------

"John Timney (Microsoft MVP)" <ti*****@despammed.com> wrote in message
news:u$**************@TK2MSFTNGP12.phx.gbl...
This has worked for me beforfe, but its IE only I think

Dim EncodedString As String = "This is a Test
String"    EndTestString"
Dim writer As New System.IO.StringWriter()
Server.HtmlDecode(EncodedString, writer)
Dim DecodedString As String = writer.ToString()
lstTest.Items.Add(DecodedString)

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
----------------------------------------------

"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@207.46.248.16.. .
Hi all,

I have a DropDownList on my page created in Design Time calledddlDate. In code, I do the following:

1 ddlDate = New DropDownList() <- To Clear the drop down list
2 ddlDate.Items.Add("HELLO")
3 ddlDate.Items.Add("WORLD")

When the page loads, how come my drop downlist is empty? Shouldn't there

be
two entries?

If I remove Line 1, then the entries are present. However, logically
speaking, why does Line 1 mess things up?

Thanks!
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/


Nov 17 '05 #6

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

Similar topics

7
by: Stephen | last post by:
I have some code which I call from a custom validator however I seem to have got the logic wrong and im having trouble figuring out how to write my code to get things to work the way I require....
0
by: huobazi | last post by:
I have many dropdownlist controls in my ascx (and use LoadControl in a aspx fiel) file,so i write a method "InitList(DropDownList list,string strsql,string TextField,string ValueField)" but when i...
6
by: VB Programmer | last post by:
I have an itemtemplate in a datagrid. I'm trying to set it's value based on data. Having no trouble with the textbox. But, how do I do the same thing for a dropdownlist???? <ItemTemplate>...
10
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
5
by: Patrick.O.Ige | last post by:
I have a parameter below and i'm passing the value via Store procedure Cmd.Parameters.Add(New SqlParameter("@ProductID", SqlDbType.Int, 1)).Value = 104 But as you can see the value "104" is hard...
5
by: Siva | last post by:
Hello I have a dropdownlist inside the gridview as a template column defined as follows: <asp:TemplateField HeaderText="Choose Location"> <ItemTemplate> <asp:DropDownList ID="ddlChooseLoc"...
0
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event,...
0
by: ana_gil | last post by:
hello i have a problem with a dropdown list i am populating from an Access table. I´ve seen this problem in other discussions but i can´t seem to find the solution. please help. my .aspx has...
4
by: pankajsingh5k | last post by:
Hi guys, These question is for all the experts... Please help me before my brain explodes The problem is again with the formview control.. I have a formview and i have to use it that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.