how do I get the index value of the item selected in a dropdownlist?

Hello friends. This is driving me crazy.

I have a table in access with the list of US states. That table has 3 column fields:
idsStateID (the key field, which is a number)
chrStateAbv (the abbreviation of the state, FL, AK, VA...)
chrStateName(the name of the state, Florida, Arkansas,...)
I have this code in a web form:
getDataFromDB(conx, "select * from ltblState", da, ds, dt, "tblStates") 'retrieves the data from the database into a datatable (dt) and assigns "tblStates" to that table
Me.droState.DataSource = dt 'the datatable containing the states
Me.droState.DataTextField = "chrStateName"
Me.droState.DataValueField = "idsStateID"
This is working fine, the dropdown list displays the states correctly.
The Problem is I can not get to retrieve the idsStateID value associated
with the state when a state is selected from the dropdownlist.
Private Sub droState_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles droState.SelectedIndexChanged
' What do I do here to get the "idsStateID" value associated with
'with the selection? The idea is to be able to do something similar to
dim selectedIndex as integer=droState.selecteditem.value
'I know that one does not work, but how do i get a hold of the
'index associated with the selection made in the dropdownlist?
End Sub
10/8/2004 5:50:09 PM 93655 articles. 6 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 43

int selIndex = droState.SelectedIndex; // will give you the INDEX number of the selected item
int idsStateID = Convert.ToInt32(droState.SelectedItem.Value); // will give you the id of the selected state
string chrStateName = droState.SelectedItem.Value; // will give you the string name of the selected state

10/8/2004 8:09:39 PM
Thank you. Well I am working on it, it looks that the problem is in loading the data from the database. It puzzels me that the list of states show, but nothing is returned...
10/8/2004 8:15:55 PM
To troubleshoot, hit the page, then view the HTML source of the page that is created. look at the dropdownlist in HTML (<select>) and see if there is a "value" attribute associated with each element in the dropdownlist. perhaps there is no value, and thus it isn't returning a value when you access the selecteditem.value.
10/8/2004 8:49:54 PM

Similar Artilces:

Getting the Selected Item of dropdownlist inside Web User Control on a Web Form
Ive got a dropdownlist control inside a web user control called Entity.ascx. This web user control is on a webform.aspx. In Entity.ascx class I created a SelectedEntity property that returns the selected item in the dropdownlist. Inside webform.aspx when btnGo is pushed I set a string and pass it in the url. I am trying to get the entity they selected via the property (SelectedEntity) inside Entity.ascx. As the SelectedEntity property tries to return the selected item in the dropdownlist I get this error: System.NullReferenceException: Object reference not set to an instance...

Getting DropDownlist's DataTextValue Selected Value Given the SelectedValue and/or Selected Item
In the codebehind, I need to extract something from the Text (displayed) value of dropdownlist's selected item and I have  the SelectedValuand and SelectedItem in hand. How can I do this?  FindControl? Item? row?   Thanks. Well, its easier than you might think. SelectedItem has a "text" property. Thats the selected text right there :)  If you need the Text of the selection, then you have to use the SelectedItem.Text property.  If you want the value (not the displayed text) the you can directly use the SelectedValue. dim sText as String = dropdown...

dropdownlist's selected index value is not printing the selected value
Here iS my code .Aspx Page <asp:DropDownList ID="ddlkeyword" runat="server" Width="204px" DataTextField="Form" DataValueField="Form" OnSelectedIndexChanged="ddlkeyword_SelectedIndexChanged" >   </asp:DropDownList> <asp:Button ID="Button1" runat="server" Text="Submit" Width="110px" OnClick="Button1_Click" /> my aspx.cs protected void Page_Load(object sender, EventArgs e) { fillddlkeyword(); }protected void Page_Init(object sender, EventArgs e) { ...

Get the item index which causes the Selected Item Index changed event.
I have a web form which has Multiple select CheckBox List. In this, i have items out of which few are selected and few are unselected. Now when i select or deselect an item, SelectedIndexChanged Event is fired. I want to find out the item which fires the selectedindex changed event. Please help me out. One option is to examine the value of Request.Form["__EVENTTARGET"]. This carries a value as CheckBoxListID$CheckedItemIndex. E.g.: cbl$4 if 5th item is cheked or unchcked.Mark replies as answers if they helped you solve the problem....

Get DataList selected item index value
Hi, I have a datalist, and within this datalist I have an image button and a Label. when the image button is clicked on the Command event I run this code.protected void getItemIDClick(object sender, CommandEventArgs e) { int X = THE INDEX VALUE OF THE SELECTED ROW Label ItemIDLabel = DataList1.Items[X].FindControl("ItemIDLabel") as Label; string itemID = ItemIDLabel.Text.ToString(); showItem(itemID); } Can someone tell me how I find the Value of the datalist index so I can find the Label control value.  thanks Use Label ItemIDLabel = (Label )DataList1.Items[...

Dropdownlist in repeater, not databound, getting value of selected Item
Hi, I have this ItemTemplate in a repeater: <ItemTemplate> <tr> <td style="width: 515px"><%# ((Item)Container.DataItem).name %> </td> <td width="96"> <asp:DropDownList AutoPostBack="true" OnSelectedIndexChanged="weightFactorSelectedIndexChanged" ID="ddWeightFactor" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> &l...

Load Text box of one web form with selected list item of list box of another web form
one help please Problem is i have two web forms  1.  ForiegnkeyTest.aspx  2. foroginkeytable.aspx   step 1 1 ForiegnkeyTest.aspx one web form <head runat="server"><script language="javascript" type="text/javascript">   function popWin()   {         var confirmWin = null;      confirmWin ='foroginkeytable.aspx','anycontent',   'width=455,height=435,status');   }  </script> &...

how can i get the selected index of the dropdownlist i selected?
i have a datagrid..which contains dropdownlist. if i select a dropdownlist of 2nd can i retreive the index from which i can identify the 2nd row dropdownlist is selected? thanks in advanceWinners Never Quits and Quitters Never Wins! You can get the selected value of the drop down list (*) or any control on the page after you submit by the following statement: MySelectedValue = Request.Form("MyDDL") ' where MySelectedValue is a variable and MyDDL is the name of the drop down list I know that you have a drop down list in a data grid, so each row will h...

getting values from a web form to windows form
Hot Requirement ..... Is there any possible of getting values from a web form to windows form ????? Yes One way i to use the WebRequest and WebResponse classes of the System.Net namespace. For example:  WebRequest request = WebRequest.Create("URL of the web page); WebResponse response = request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string content = reader.ReadLine(); ....    Reza Nassabehwww.professionalcsharp.comDon't forget to click "Mark as Answer" on the post that helped you. That way fut...

After selecting DropDownList Item, how to set DropDownList Item so that it corresponds to new selection.
Hi,  I'm having difficulty retaining DropDownList selected item so that it corresponds to the new page that is called when the item is selected. i.e DropDownList contains 4 Items Item1 Item2 Item3 Item4 Each item when selected is bound to a corresponding page. Item1.aspx Item2.aspx Item3.aspx Item4.aspx If the default page is Item1.aspx...if I select Item3 in the DropDownList, the page Navigates to the corresponding page - Item3.aspx.  I want the DropDownList to remain displaying Item3 and not the default Item.  Thank you. for master pag...

Form: Focus on selected values in dropdownlists, Refresh after selection and hidding formfields based on selection.
Hello again,I have a form with several dropdown lists. Depending on the selected value in the dropdown lists other fields become available in that same form. It is working in classic ASP in combination of JavaScript. I want to migrate it to ASP.NET. I have posted a part of the form at the end of this post.My questions:1. I use <option <%If iFood="0" then%>selected<%End If%> value="0">No value selected</OPTION> to select the selected item when the form is reloaded after the selecting. I know that this also works in ASP.NET, but isn't there a typical ASP....

How Select one dropdownlist value using down arrows corresponding other dropdownlist value are select
I am using two dropdownlist box.One is used for country selection. other one is used for state selection.I am using dropdown selectedindexchanged event. when i click country dropdownlist corresponding state is selected in state dropdownlist box. How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.R.Karthikeyan   kartmca: How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.Generally, we don't implmenet...

DropDownList Selected value to set gridview selected Index and page
I have a dropdownlist and a gridview that is bound to the same objectdatasource. In the gridview I am allowing paging.  When user select an item in the dropdownlist list I want to position the gridview selected value to that page and that record. Is there an easy way to do this. I tried this code Protected Sub GrdMyIssues_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GrdMyIssues.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then 'find the position data selected in the If e.Row.Cells(1).Text = Me.ViewSt...

How to get selected item(s) from a select form with Intraweb? [Edit]
Hi Everyone! I am going to convert our Delphi Client/Server Applications to Intraweb applications. I never use Intraweb before this month. Can anyone tell me how to do the folling with Intraweb? Any Sample do that? ---------------------------------------------------------------------------------------- Open a form(contain a Grid), and select one or more items, then bring the selected item(s) back to calling form. ---------------------------------------------------------------------------------------- Thanks to all. from: Slong Tseng. Edited by: Big Two on Jun 8, 2014 6:10 PM ...

Web resources about - how do I get the index value of the item selected in a dropdownlist? -

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 11/25/2015 8:04:17 AM