473,804 Members | 2,034 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 3810
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
4283
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
10343
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
10331
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
10087
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...
0
9166
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7631
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
6861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4306
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
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.