473,657 Members | 2,556 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDownList Selecting item

Using Visual Studio.net 2003 to create an aspx web form I am having a
problem selecting an item from DropDownListBox with id= ListBoxStudies.
I can see the items from the bound database table but when I click on an item
the selected item stays at itemindex 0. What must I do to have the
itemindex change when I click on an item. What's missing from the following
code?
ListBoxStudies. DataSource = BICDataSet.Tabl es("protocols" )
ListBoxStudies. DataTextField = "Study_name "
ListBoxStudies. DataValueField = "irb_number "
ListBoxStudies. DataBind()
I have tested this using a submit button and the _SelectedIndexc hanged event
and I still always get selectedindex = 0.

Private Sub DropDownListStu dies_SelectedIn dexChanged(ByVa l sender As
System.Object, ByVal e As System.EventArg s)
Dim study_name As String = Session("study_ name")
study_name = ListboxStudies. SelectedItem.Te xt
End Sub

--
Derek V. Taylor
UCI Brain Imaging Center
Mar 28 '06 #1
2 1769
You may want to ensure you're binding only on the initial page load and not
on each postback, which could effectively overwrite the user's selection.
Here's an example:

'Page_Load event...
If Not Page.IsPostBack () Then
ListBoxStudies. DataSource = BICDataSet.Tabl es("protocols" )
ListBoxStudies. DataTextField = "Study_name "
ListBoxStudies. DataValueField = "irb_number "
ListBoxStudies. DataBind()
End If

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Derek Vincent" <De**********@d iscussions.micr osoft.com> wrote in message
news:E2******** *************** ***********@mic rosoft.com...
Using Visual Studio.net 2003 to create an aspx web form I am having a
problem selecting an item from DropDownListBox with id= ListBoxStudies.
I can see the items from the bound database table but when I click on an
item
the selected item stays at itemindex 0. What must I do to have the
itemindex change when I click on an item. What's missing from the
following
code?
ListBoxStudies. DataSource = BICDataSet.Tabl es("protocols" )
ListBoxStudies. DataTextField = "Study_name "
ListBoxStudies. DataValueField = "irb_number "
ListBoxStudies. DataBind()
I have tested this using a submit button and the _SelectedIndexc hanged
event
and I still always get selectedindex = 0.

Private Sub DropDownListStu dies_SelectedIn dexChanged(ByVa l sender As
System.Object, ByVal e As System.EventArg s)
Dim study_name As String = Session("study_ name")
study_name = ListboxStudies. SelectedItem.Te xt
End Sub

--
Derek V. Taylor
UCI Brain Imaging Center

Mar 29 '06 #2
Wow! That was great; I gave you a direct question and you gave me a direct
and effective response. The application works: All is love; all is peace;
all is harmony.
--
Derek V. Taylor
UCI Brain Imaging Center
"Steve C. Orr [MVP, MCSD]" wrote:
You may want to ensure you're binding only on the initial page load and not
on each postback, which could effectively overwrite the user's selection.
Here's an example:

'Page_Load event...
If Not Page.IsPostBack () Then
ListBoxStudies. DataSource = BICDataSet.Tabl es("protocols" )
ListBoxStudies. DataTextField = "Study_name "
ListBoxStudies. DataValueField = "irb_number "
ListBoxStudies. DataBind()
End If

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Derek Vincent" <De**********@d iscussions.micr osoft.com> wrote in message
news:E2******** *************** ***********@mic rosoft.com...
Using Visual Studio.net 2003 to create an aspx web form I am having a
problem selecting an item from DropDownListBox with id= ListBoxStudies.
I can see the items from the bound database table but when I click on an
item
the selected item stays at itemindex 0. What must I do to have the
itemindex change when I click on an item. What's missing from the
following
code?
ListBoxStudies. DataSource = BICDataSet.Tabl es("protocols" )
ListBoxStudies. DataTextField = "Study_name "
ListBoxStudies. DataValueField = "irb_number "
ListBoxStudies. DataBind()
I have tested this using a submit button and the _SelectedIndexc hanged
event
and I still always get selectedindex = 0.

Private Sub DropDownListStu dies_SelectedIn dexChanged(ByVa l sender As
System.Object, ByVal e As System.EventArg s)
Dim study_name As String = Session("study_ name")
study_name = ListboxStudies. SelectedItem.Te xt
End Sub

--
Derek V. Taylor
UCI Brain Imaging Center


Mar 29 '06 #3

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

Similar topics

3
1404
by: KavvY | last post by:
How can I get a selected index changed event to fire, when the DropDownList only has one item? Thanks, Rich.
0
1392
by: 00_CumPeeWearD12 | last post by:
How to add background color to DropDownList item? I can do this in HTML: <select> <option>test1 <option style='background:red'>test2 <option>test3 </select>
4
1627
by: dhnriverside | last post by:
Hi guys I've got a dropdownlist which is being databound to an sqldatareader at runtime. I want to add an extra Item to the list, not from the database. I know I can do this with ddl1.Items.Add(new ListItem("text", "value")); works fine. However, if I put this above my DataBinding code, it doesn't
1
7415
by: g | last post by:
I have a user control that contains a dropdownlist. Using a public property, I can get the selected item. However, I am unsure of how to use that same public property to set the selected item. Here's my code: private string m_item = ""; public string Item { get {
1
1746
by: John | last post by:
If you set DropDownList.SelectedValue to an item not in the list, shouldn't an exception be thrown? ie: <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem Text="1" Value="1"></asp:ListItem> <asp:ListItem Text="2" Value="2"></asp:ListItem> <asp:ListItem Text="3" Value="3"></asp:ListItem> </asp:DropDownList> Then in the codebehind:
1
1469
by: sean.polacsek | last post by:
Hi there, I have a curious problem. I have DropDownList that gets bound to datatable during PreRender. Straight after binding I set the SelectedValue of the DropDownList. When the page is rendered no value is selected in the list. Here is the kicker though: When I check the HTML source, the rendered HTML is as it should be. ie. The SELECT control has the correct OPTION
1
1547
by: rockdale | last post by:
Hi, all Is there a way to dynamically attach a regularexpressionvalidator to a textbox base on dropdownlist selected item? Let's say I have a dropdownlist list all contact type - phone, cell, email ...etc and a textbox that allow user to type in their contact info. When they choose email, I want attach the regularexpressionvalidator of email to the textbox, when the ddl selected phone, then I want attach phone regExp to the same...
2
1354
by: yogeshtiwarijbp | last post by:
when i select data from the drop down list box and display data in the datagrid the first data in the dropdownlistbox not shown the requireddata in the grid. i have used 2 tables and after selecting the data the required data is displayed after executing a join query. i have wriitten code in selectindexchanged of dropdownlist box
0
1083
by: Jeff | last post by:
Hi asp.net 2.0 My webpage has a DataList containing a TemplateField (ImageButton). When the ImageButton is clicked it becomes the selected ImageButton. This works okay as it is. But this isn't an ideal solution, because CommandArgument in this solution will contain a counter (first element have value 0, then 1 etc). Instead I think it would be better to have some kind of Id from Car object stored in the CommandArgument so I easier...
0
8397
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
8310
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,...
0
8827
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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...
0
8605
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
7333
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...
0
5632
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();...
1
2731
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
1620
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.