473,888 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Drop down list does not see the selected item!

My drop down list is populated from a static array in my codebehind (c#)
code.
I set the selected index based on some known values(from DB), when the
screen shows up, dropdown list shows that the the first items is selected and
not the one assigned.

Please note that if I hardcode the dropdown items inside the .aspx file,
everything works fine.

Please point me to examples(infopa th examples somehow don't show up for me!).

Thanks
Nov 18 '05 #1
4 2719
It'd be helpful if you showed us what you have so far, such as how the
dropdownlist is populated (are you binding, or looping through your array
and adding items), and how the selected item is being set.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Merdaad" <Me*****@discus sions.microsoft .com> wrote in message
news:D0******** *************** ***********@mic rosoft.com...
My drop down list is populated from a static array in my codebehind (c#)
code.
I set the selected index based on some known values(from DB), when the
screen shows up, dropdown list shows that the the first items is selected and not the one assigned.

Please note that if I hardcode the dropdown items inside the .aspx file,
everything works fine.

Please point me to examples(infopa th examples somehow don't show up for me!).
Thanks

Nov 18 '05 #2
Thanks for replying.

Here is my code:
String[] usStates;
usStates = (String[]) Application.Get ("states");
bStDDList.DataS ource = usStates;
bStDDList.DataB ind();
......
...

bStDDList.Selec tedIndex = Convert.ToInt16 (DataBinder.Eva l(custDataSet,
"Tables[getCustomerData].DefaultView.[0].bState",""));

/*debugger shows bStDDList.Selec tedIndex to be the correct index*/

"Karl Seguin" wrote:
It'd be helpful if you showed us what you have so far, such as how the
dropdownlist is populated (are you binding, or looping through your array
and adding items), and how the selected item is being set.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Merdaad" <Me*****@discus sions.microsoft .com> wrote in message
news:D0******** *************** ***********@mic rosoft.com...
My drop down list is populated from a static array in my codebehind (c#)
code.
I set the selected index based on some known values(from DB), when the
screen shows up, dropdown list shows that the the first items is selected

and
not the one assigned.

Please note that if I hardcode the dropdown items inside the .aspx file,
everything works fine.

Please point me to examples(infopa th examples somehow don't show up for

me!).

Thanks


Nov 18 '05 #3
Typically, you set the selectedindex via:

bstDDList.Selec tedIndex =
bstDDList.Items .IndexOf(bstDDL ist.Items.FindB yValue(some string value))

I imagine bState is the actual state code, which probably doesn't match up
to the array index of your list item...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Merdaad" <Me*****@discus sions.microsoft .com> wrote in message
news:56******** *************** ***********@mic rosoft.com...
Thanks for replying.

Here is my code:
String[] usStates;
usStates = (String[]) Application.Get ("states");
bStDDList.DataS ource = usStates;
bStDDList.DataB ind();
.....
..

bStDDList.Selec tedIndex = Convert.ToInt16 (DataBinder.Eva l(custDataSet,
"Tables[getCustomerData].DefaultView.[0].bState",""));

/*debugger shows bStDDList.Selec tedIndex to be the correct index*/

"Karl Seguin" wrote:
It'd be helpful if you showed us what you have so far, such as how the
dropdownlist is populated (are you binding, or looping through your array and adding items), and how the selected item is being set.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Merdaad" <Me*****@discus sions.microsoft .com> wrote in message
news:D0******** *************** ***********@mic rosoft.com...
My drop down list is populated from a static array in my codebehind (c#) code.
I set the selected index based on some known values(from DB), when the
screen shows up, dropdown list shows that the the first items is selected
and
not the one assigned.

Please note that if I hardcode the dropdown items inside the .aspx
file, everything works fine.

Please point me to examples(infopa th examples somehow don't show up

for me!).

Thanks


Nov 18 '05 #4
I think the result is the same either way.

tw. How do you add to a drop down list after it's bound to its datasource.
I have tried ....items.inser t and ..items.add neither one works. I can't
even modify the items that are already there.

Thanks

"Karl Seguin" wrote:
Typically, you set the selectedindex via:

bstDDList.Selec tedIndex =
bstDDList.Items .IndexOf(bstDDL ist.Items.FindB yValue(some string value))

I imagine bState is the actual state code, which probably doesn't match up
to the array index of your list item...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Merdaad" <Me*****@discus sions.microsoft .com> wrote in message
news:56******** *************** ***********@mic rosoft.com...
Thanks for replying.

Here is my code:
String[] usStates;
usStates = (String[]) Application.Get ("states");
bStDDList.DataS ource = usStates;
bStDDList.DataB ind();
.....
..

bStDDList.Selec tedIndex = Convert.ToInt16 (DataBinder.Eva l(custDataSet,
"Tables[getCustomerData].DefaultView.[0].bState",""));

/*debugger shows bStDDList.Selec tedIndex to be the correct index*/

"Karl Seguin" wrote:
It'd be helpful if you showed us what you have so far, such as how the
dropdownlist is populated (are you binding, or looping through your array and adding items), and how the selected item is being set.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Merdaad" <Me*****@discus sions.microsoft .com> wrote in message
news:D0******** *************** ***********@mic rosoft.com...
> My drop down list is populated from a static array in my codebehind (c#) > code.
> I set the selected index based on some known values(from DB), when the
> screen shows up, dropdown list shows that the the first items is selected and
> not the one assigned.
>
> Please note that if I hardcode the dropdown items inside the .aspx file, > everything works fine.
>
> Please point me to examples(infopa th examples somehow don't show up for me!).
>
> Thanks


Nov 18 '05 #5

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

Similar topics

1
1483
by: Paul M | last post by:
Hi folks, When I set the datasource of a dropdown list and bind it, the drop down list always defaults to the first item in the list. I need it to default to Nothing or NULL or whatever it is now in .NET. The situation I've got is a group of combo boxes that interelate. So if you select item 1 from drop down A, you are prompted to select an item in drop down B and if you select item 2 from drop down A you are prompted to select an...
3
26346
by: Stephen Adam | last post by:
Hi there, I'm sure i'm missing something really simple here, all i want to do is get the value of the selected item in a list box. Even after much fiddling about last night I still could not get my code to work. Below is some code which highlights my problem. All I want to do is set the lable control's text property to the value of the selected drop down list value - in this example i've shown the three ways i've tried. Please help!
2
2118
by: Joey Liang via DotNetMonster.com | last post by:
Hi all, I am new in asp.net, i encounter some problems in using drop down list and datagrid. I have manage to bind the data into datagrid but i wanted to bind the data into the datagrid accroding to the selected brand from the drop down list. I do not have any idea how to do it. Does anyone knows how to bind the data in to datagrid accroding to the drop down list selected item? if there is a way would u mind paste the code or any...
4
1481
by: Chris Kettenbach | last post by:
Good Morning, Quick question, I have an EditItemTemplate inside a datagrid. It should contain a drop down list of possible choices. I have an EditCommandColumn. The drop dow list column should initially contain the value of the field. This works fine with <ItemTemplate><%# Container.DataItem("NameType")%></ItemTemplate> The desired effect is for the drop down list to databind to a query to show possible choices when the user clicks...
2
3045
by: Dave A | last post by:
I am stuggling with databinding a drop down list, hooking into the SelectedIndexChanged and attempting to avoid using the viewstate. The drop down list is quite large so I would prefer to avoid using the view state so I set EnableViewState on the page to false. To enable the drop down list to bind to a datasource I bind it during the OnInit. I do a response.Write during the SelectedIndexChanged event to verify that the event fires. ...
3
3000
by: John Walker | last post by:
Hi, On an ASP.NET page I have a drop down list control. When the user pulls down the list and makes a selection, I perform validation, and if the validation fails I want the selected item in the drop down box to go back to what the value was before the user tried to change it, but at that point I will not know what the original value was. Or is there a drop down control "revert" method, or is there any way of knowing what the original...
5
12264
by: Ajith Menon | last post by:
I need to select multiple entries in the drop down list. E.g. Search a string in languages like C#, VB, Java etc. These entries are in drop down. So i need to multi select to search in multiple languages 1. One of the option could be to have a check box beside each entry in drop down. Do any one have an idea how to do this. Solution in C# is required but even if its unmanaged code is OK.
0
9800
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10885
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
9597
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
7990
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
7148
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
5817
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
4642
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
4244
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3252
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.