Getting DropDownlist's DataTextValue Selected Value Given the SelectedValue and/or Selected Item

In the vb.net 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.

0
jcnet
11/6/2006 10:20:50 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

4 Replies
3254 Views

Similar Articles

[PageSpeed] 49

Well, its easier than you might think.

SelectedItem has a "text" property. Thats the selected text right there :) 

0
shados
11/6/2006 10:31:43 PM

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 = dropdown1.SelectedItem.Text
dim sValue as Integer = cint(dropdown1.SelectedValue)

<asp:Dropdownlist id="Dropdown1" runat="server" DataValueField = "employeeID" DataTextField="EmployeeName" DataSourceID="Employees" />

0
codeasp
11/6/2006 10:34:13 PM
jcnet:

In the vb.net 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.

you can directly get selected text..

DropDownList1

.SelectedItem.Text


My Blog


"Don't be afraid to be wrong; otherwise you'll never be right."
0
budugu
11/6/2006 10:35:16 PM

OK, I am sure i don't understand your question.  Given that here is the solutioon to what I understand your Q to be.

Mycbo.SelectedValue.Substring(0, 3) ' Get the first 3 chars

Joe Johnston
If a picture is worth a 1000 words, a sample application is worth a 1000 blog entries
Remember the Constitution!
Dont forget to mark posts answered and resolved (if they are)
0
khaos
11/6/2006 10:43:16 PM
Reply:

Similar Artilces:

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) { ...

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...

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 ...

dropdownlist
Hi folks, I am a novice - simple. I have done my homework by reading articles online and as a last resort coming over here. The Problem I am not able to retrieve the Text and Value selected from the dropdownList (dynamically populated) user control. The application is instead is always returning me the first item in the dropdownlist (even if the user selected something else). Here are some related pieces of code. AddNewSubCategory.aspx Contains this line of dropdownlist code. (pretty standard) This drop down list is being dynamically populated by the Sub BindCategoryList(...

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 can i get the secondary dropdown's selected value when there is no chosen item
Hi i have a problem with my cascading dropdown toolkit. I use this toolkit filtering data in my project. When i select in first (primary) dropdown and not select in the second (secondary) dropdown and then click the filter button it gives error in my search page. It gives error because my secondary dropdown returns null it hasnt got any selected value.<asp:DropDownList ID="ddlSirketler" runat="server" AppendDataBoundItems="true"> <asp:ListItem Selected="True" Value="0" Text="┼×irket Se├žiniz"/>...

Getting the selected value from an embedded DropDownList in GridView's ItemTemplate when Updating
Hi all, I wrote about this problem but none could help me so I'm posting it again with hope someone help me to solve this problem.OK. I have a GridView(ProductsGridView) bound to an ObjectDataSourceObject. One of the Columns is with DDL, which takes the CategoryID from the Product. The problem comes when I start to Edit the Row, it goes to edit mode, I change the Category for example, and then when I hit the Update button the value from the DDL is not Updated. It still has the value which it has at first. How can I get the Updated value and give it to my Business Object(Product)? Th...

Default value for Dropdownlist that get's it's value from Database.
Hi, I am using an Object Data Souce to retrieve the value of a Dropdownlist from a table on MS SQL server 2005. I want to make a default value appear on the Dropdownlist intially, should i enter the default value into the database table or is that a better way of doing it? Any suggestions will be very much appreciated. E  No need for database just set sekected value after databingind protected void Page_Load(object sender, EventArgs e) { DataBind(); ListItem defaultItem = new ListItem("Select a Person", "-1"); th...

Should FxOS's "select all" really be docshell's "select all" (which tries to select everything in the document)?
The specs on https://bugzil.la/1023688 (specifically https://bug1023688.bugzilla.mozilla.org/attachment.cgi?id=8548761 which of the two is the one that discusses "select all") don't directly address the issue of containment for non-editable areas. Our implementation, as I trace it, ends up invoking do_selectAll on the docshell which tries to select *everything* editable in the entire page. This came to my attention while looking at https://bugzil.la/1152172 which is an email bug where select all was selecting both the selectable content on the current message rea...

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...

How to change the dropdownlist's value from database on selection of 1 st dropdownlist
Hi Friends, I have 2 dropdownlist. 1 for country and 1 for state. When i will select any coutary according to that all state related to that countary shoud change in dropdownlist. I have to fatch both dropdownlist's value from sqlserver database. And i also don't know how to make relationship to get all value in aspx page. so please also tell me what should i made in database means primary foreign key concept. I will be very thankful if you can send me code for that.    There will be 2 tables in the database, Country with country_id as primary key. Another table Stat...

dropdownlist
i have created a dropdown list that is populated from a sqlserver datasource. i have a separate sql command which uses the dropdownlist.selected value as a parameter and returns the command value to a label.  it mostly works fine but with one problem. when the page loads, the label value is null, because it doesn't seem to treat the dropdownlist default value as a selected value. when i use the dropdownlist to select a value, this is fine and the label begins to display the expected value. is there anyway I can make the default value when the page is loaded act like a manual...

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...

superreview requested: [Bug 112281] ctrl+shift+click whle making range selections in form <select> shouldn't wipe out other selected items : [Attachment 135533] Proposed patch
Boris Zbarsky (real world intrudes) <bz-vacation@mit.edu> has asked Robert O'Callahan <roc@ocallahan.org> for superreview: Bug 112281: ctrl+shift+click whle making range selections in form <select> shouldn't wipe out other selected items http://bugzilla.mozilla.org/show_bug.cgi?id=112281 Attachment 135533: Proposed patch http://bugzilla.mozilla.org/attachment.cgi?id=135533&action=edit ------- Additional Comments from Boris Zbarsky (real world intrudes) <bz-vacation@mit.edu> roc, what do you think? ...

Web resources about - Getting DropDownlist's DataTextValue Selected Value Given the SelectedValue and/or Selected Item - asp.net.web-forms

Resources last updated: 1/15/2016 6:26:15 AM