473,805 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDownList Problem

Hi,
I am using a DropDownList and populating with items. One of the items
is set as blank("").

I need to check that the items selected from this DropDownList is not
that value but another one.

I am using the following code:
string result =DropDownList.S electedItem.Tex t;

The value of the result is always being an empty string(""), even when
I select an item that has text in it.

Can someone help me out.
Thanks in Advance
Nov 19 '05 #1
7 3811
How and when are you populating the items? In Page_Load, protected by a
Page.IsPostBack ?
Defined in one the .aspx html page?

bill
"Xarky" <be*********@ya hoo.com> wrote in message
news:bc******** *************** **@posting.goog le.com...
Hi,
I am using a DropDownList and populating with items. One of the items
is set as blank("").

I need to check that the items selected from this DropDownList is not
that value but another one.

I am using the following code:
string result =DropDownList.S electedItem.Tex t;

The value of the result is always being an empty string(""), even when
I select an item that has text in it.

Can someone help me out.
Thanks in Advance

Nov 19 '05 #2
I'm populating it during the Page_Load method.

Items I add are being all shown ind dropdownList, but as reported an
empty string is being reported in SelectedItem.Te xt

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #3
Hi Xarky,
As William pointed out, the problem lies in the Page.IsPostBack property..

Need help, post the code...

Happy Coding..
"Xarky" <be*********@ya hoo.com> wrote in message
news:bc******** *************** **@posting.goog le.com...
Hi,
I am using a DropDownList and populating with items. One of the items
is set as blank("").

I need to check that the items selected from this DropDownList is not
that value but another one.

I am using the following code:
string result =DropDownList.S electedItem.Tex t;

The value of the result is always being an empty string(""), even when
I select an item that has text in it.

Can someone help me out.
Thanks in Advance

Nov 19 '05 #4
Does your page load look something like this.

private Page_Load( ... )
{
if ( Page.IsPostBack == false )
LoadDDLItems();
}

or
private Page_Load( ... )
{
LoadDDLItems();
}

If your looks like the second approach, every postback you are dumping what
the user selected and recreated all the items. During your LoadDDLItems
method, you probably also are adding the blank record at position 1, and
might even be setting the index.

Make sure you are only binding the data to your DropDownList when the
IsPostBack property of the Page is false.

Post your code if you need more help.

bill

"xarky d_best" <be*********@ya hoo.com> wrote in message
news:ee******** ******@TK2MSFTN GP12.phx.gbl...
I'm populating it during the Page_Load method.

Items I add are being all shown ind dropdownList, but as reported an
empty string is being reported in SelectedItem.Te xt

*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #5
Hi,
What code exactly do I need to post. Is this enough?

<asp:DropDownLi st id="dropDownLis t" style="Z-INDEX: 109; LEFT: 168px;
POSITION: absolute; TOP: 112px" tabIndex="4" runat="server"
Height="24px" Width="184px" Font-Size="Medium"></asp:DropDownLis t>

*** in Page_Load() ****
dropDownList.It ems.Clear();
dropDownList.It ems.Add("");
foreach(string type in schoolTypes)
{
dropDownList.It ems.Add(type);
}

schoolTypes is an arrayList, where its data is being retrieved from a
database.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #6
You need to place you .Clear(), .Add() code inside a if statement

page_load

if ( Page.IsPostBack == false )
{
dropDownList.It ems.Clear();
dropDownList.It ems.Add("");
foreach(string type in schoolTypes)
{
dropDownList.It ems.Add(type);
}
}

HTH,

bill

"xarky d_best" <be*********@ya hoo.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi,
What code exactly do I need to post. Is this enough?

<asp:DropDownLi st id="dropDownLis t" style="Z-INDEX: 109; LEFT: 168px;
POSITION: absolute; TOP: 112px" tabIndex="4" runat="server"
Height="24px" Width="184px" Font-Size="Medium"></asp:DropDownLis t>

*** in Page_Load() ****
dropDownList.It ems.Clear();
dropDownList.It ems.Add("");
foreach(string type in schoolTypes)
{
dropDownList.It ems.Add(type);
}

schoolTypes is an arrayList, where its data is being retrieved from a
database.

*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #7
Thanks, problem solved

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #8

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

Similar topics

2
3424
by: Brennon Arnold | last post by:
I have a problem that I figured would be relatively common, but have been unable to find any information on it as of yet. I have a page that contains two DropDownList controls, with the second being dependent on the value of the first. My DropDownList control definitions look like this: <asp:dropdownlist id="ddlLocCty" runat="server" CssClass="SmlBox" AutoPostback="True" CausesValidation="False"></asp:dropdownlist> <asp:dropdownlist...
12
2810
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option Description"></asp:BoundColumn> <asp:TemplateColumn runat="server" HeaderText="Id Type Option" "> <itemtemplate> <asp:label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "TypeOption") %>' /> <asp:label runat="server" ID="LlbTypeOption" Visible=False...
2
467
by: Antonio D'Ottavio | last post by:
Good Morning, In my web page I've a datalist that is sourced by a database, the problem is that I want that one of the column of the datalist contain a dropdownbox that also is sourced by a table in the database. <asp:DropDownList id="ComboTipoPartita" runat="server" DataValueField="IDTipoPartita" DataTextField="DescrizioneTipoPartita" DataSource="<% BindComboTipoPartita() %>"
1
2002
by: Antonio D'Ottavio | last post by:
Good morning, I've a problem with a dropdownlist located inside any row of a datalist, I fill both datalist and dropdownlist at runtime, the problem is with the dropdownlist infact using the event OnItemDataBound I can fill it but it is impossible for me to load the right selectedItem.Value , infact looking at the html page produced by the server I've this strange code : <select name="MyDataCampi:_ctl1:ComboTipoPartita"...
10
10773
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 = true; Where endTime is a string containing "15".
4
2013
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet, when the datagrid enters it's own OnPreRender, the selected index has reverted to zero. I created a debug version of the dropdown list which inherited from dropdownlist and overrode the selected index property to trace.write whenever it was...
0
1275
by: Juanjo | last post by:
Hi, Before, I was working with Asp.net 1.0 and datagrid. I posted a question for this issue. The solution of this problem is load the second dropdownlist on the selectedindexchanged event of the first dropdownlist. Now, I'm working with ASP.net 2.0 and the gridview. I apply the same method but the second dropdownlist don't shows the rows filtered, it shows the rows filtered when the gridview was loaded for the first time.
3
10592
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 UpdatePanel to force a postback via JS. The user uses these two DropDownList controls to create...
1
4948
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, the following error occurs: 'ddlAssignedTo' has a SelectedValue which is invalid because it...
6
4284
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs , i.e. except of fist dropdown list no dropdownlist boxes are generating a postback.here is a code . protected void Page_Load(object sender, EventArgs e) { int selected_question = (int)Session; if (!Page.IsPostBack) { display_blueprint(); string...
0
9718
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10368
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10107
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.