Control.Value and Control.SelectedItem.Value

Can someone explain to me the difference between say, Dropdownlist.SelectedItem.Value and Dropdownlist.SelectedValue??

Just curious,
Thanks!
Tim

0
tbraga
3/5/2008 5:13:11 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

2 Replies
1016 Views

Similar Articles

[PageSpeed] 23

These are going to return the same thing. dropdownlist.selectedvalue is a shortcut to get the currently selected value in the dropdown. If that is all you want then you can just use that. If you want to access the currently selected item you can use dropdownlist.selecteditem and that return the item and you can then access any of the item's properties, including in this case the value property. 


If this post answered your question please remember to 'Mark as Answer'!
0
bpag
3/5/2008 5:45:23 PM

Hi tbraga,

SelectedValue  represent:

Gets the value of the selected item in the list control, or selects the item in the list control that contains the specified value.

public virtual string SelectedValue { get; set; }

it is readable and writable. the following code is its function realization.

public virtual string SelectedValue
{
    get
    {
        int selectedIndex = this.SelectedIndex;
        if (selectedIndex >= 0)
        {
            return this.Items[selectedIndex].Value;
        }
        return string.Empty;
    }
SelectedItem   represent:

Gets the selected item with the lowest index in the list control.

public virtual ListItem SelectedItem { get; }
You can get the selected item, it is readable only.
The following code is the function realization.
public virtual ListItem SelectedItem
{
    get
    {
        int selectedIndex = this.SelectedIndex;
        if (selectedIndex >= 0)
        {
            return this.Items[selectedIndex];
        }
        return null;
    }
}
From the above code, it return the same value for the control.selectvalue and control.selectitem.value.
Thanks.
Hope it helps,
Hua Jun

Sincerely,
Hua Jun Li
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hua
3/7/2008 3:36:49 AM
Reply:

Similar Artilces:

when loading a previously created record on to form, some controls are missing values(controls are depended on values selected in other controls)
Hello - I have created a page for Editing records.  this page will open up a chosen record and allow user to edit the data.On the form, I have 3 drop down lists.   The second dropdown list should fill values depending on value chosen in first dropdown list.  The third dropdown list should show/fill values depending on value chosen in second dropdown list.So taking this into count, i have several records with various data.  When I open-up/load a record in Edit form, only the first dropdown list has a value selected that was the pre-existing va...

Passing values from a parent web control to child web control
I have a parent control which called CONTROL1 and a child control witch called CONTROL2 I would link to pass a value from the parent control to the child control. In the parent control(CONTROL1) I have the following Event Handler . private void btn_Handler(object sender, EventArgs e) { …      if (Page.IsPostBack) {              // Send the officer names to the child controls.             if(m_nameList.SelectedItem.Text != "")     ...

Clearing Web Controls Values from a Web Form
I have a web form and after a user submit it I want to clear the form so that they may submit another entry. I have seen examples in VB of how to loop thru a web form and clear the controls, but I need a C# solution. I have tried the following code, while it does not give me an error, it does not clear the controls on the form. Any suggestions? Thanks! foreach (Control parent in Page.Controls)         {             foreach (Control child in parent.Controls)           ...

Pass 1 control value to another control value
I have this form, is the detailsview, and in edit mode, I have a link that you click to open up a small dhtml window (not a new window but more like a layer so everything is on the same page).  When I select an item from the dhtml window, it puts the value into a textbox.  I then have a button I click and I want to pass that value from that textbox to the textbox in the detailsview.  When I click the button, the value is not passed. Here is the code I use for getting the value from the dhtml window and assigning it to the detailsview textbox: If e.CommandName = "pi...

Retreiving a value from a web form within a web user control
Hi  I have a page (web form) that retreives some data from a database. To be more specific: at some point when user clicks a button (in the web form) there is some ID number retreived from a database in code behind. At the same time the Visible property of the nestet web user control is chamged to true. I want than forward the ID to the web user control so that a grid view can load data from a database for that ID. How can I access that data (the ID) within a web user control context nested in that page?  Kind regards   Check this ;ink  http://www.codeproject.com/K...

Web custom control does not maintain values of child controls
Hello everybody A few days now, I am struggling with a custom web control I am creating, which consists of 3 drop down lists (country/city/hotel).Procedure is simple: On country change, I have to fill the cities with autopostback, and on city change I have to fill hotels again with auto postback. I tried many many methods and I am confused... The best I managed to make is keep the state of countries, and render it with the selected country, selected while filling cities with apporpriate data, however I cannot manage to do the same with the cities/hotels since sities does not keep selected va...

Setting the Parameter Value to the Property Value of a Web Control
I want to filter my DetailsView with a declarative parameter. In my case, I am setting the SqlDataSource's parameter values based on the value of 2 TextBox controls on the page. I have a SP that does a SELECT based on 1 of the parameters passed in (either an ID or phone number). Param Name          Value MemberID          TextBox1.Text Phone               TextBox2.Text I want to assign a default value of 'null' for b...

Controlling web control instances on Web Form
I have created a composite control, extending functionality of the Hidden Control. However, I would like to prevent the user from adding this control to the page multiple times. I only want one instance of the control on the Web Form. What setting in my project to I adjust to enable this functionality? I can not find it in any of the books that I have referenced. Is this a setting or is this code that has to be added to the inheriting class. Looks like there is no standard apporach. But I'd consider using static field to count number of created objects and throw exception if second object ...

How to maintain form controls value after user control post back?
 hello experts, I have created filter grid in asp.net & C#.My form design has contains 3 dropdown controls and Filter grid(User control).Its working fine(filter), but one problem arise.the form controls are clear when i filter a grid(post back).I tried to reterive values using view state, hidden controls, i got only null values.Anyone please help, its urgent to me. Its my user control code.FilterGrid.aspx<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FilterGrid.ascx.cs" Inherits="FilterGrid" %><style type = "text/css&...

values of web controls in user control can not be access from other pages???
I have aspx page(brief code: includes ascx file) <%@ Register Src="reseller.ascx" TagName="reseller" TagPrefix="uc1" %> <form id="form1" runat="server"> <uc1:reseller ID="idreseller" runat="server" /> </form> the code for asxc file . i have the PostBackUrl to reseller.aspx <asp:TextBox ID="txtPostCode" runat="server" CssClass="form1" Width="50" MaxLength="4" /> <asp:ImageButton ID="ibtn"  ImageUrl="images/searchbutton.jpg" PostBackUrl="~/reseller.aspx" runat="server"  /> In my reseller page i try to read the post value of control txt...

How to get the HREF value of the Anchor tag in a web page using the web browser control in vb.net
Hi Friends,               i have a webserver control in my application.i load the web browser control on a button click using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click                AxWebBrowser1.Navigate("http://www.rateitall.com/i-322335-.aspx", False) End sub once the page is loaded in the browser i want the <a> HREF value in that page.For example if that page has ...

How to retrieve web form values with a Webbrowser control
Hi all, From a stand alone applicaiton written in visual basic, how can I retrieve values form a asp.net form using the WebBrowser control?     jsn1: Hi all, From a stand alone applicaiton written in visual basic, how can I retrieve values form a asp.net form using the WebBrowser control? Hi jsn1, Try to use following code to solve your problem, Me.webBrowser1.Document.All("UserId").GetAttribute("value") Hope it helps, Hong Gang  Hong-Gang ChenMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and ...

Problem in Passing controls values between web forms
Hi friends          i have problem with my .aspx application inwhich i want to store the values of controls in a webform to the variables in the other one.         My application is like, i have a mainpage in which i have an <IFRAME>, into which i call other 3 .aspx pages one by one using links. Now i wants to save the values of controls in those all three child page in my mainpage variables and from that i want to store them in database.        Please help me ou...

Passing values to a Windows Control in a Web Form
I have created my grid in windows and am hosting it in an asp.net page. My question is can I pass session variable to the winform from my asp.net form and vice versa? Any help is greatly appreciated I don't believe you are able to do this as a session variable.  Now I might not be accurate in my terminology here but I think it because of how session states are handled.  They are in two seperate system processes (or pools). So for instance, when a user launches your asp.net form, it uses the aspnet_wp.exe.When a user launches your web form, it uses your project.exe Both of thes...

Web resources about - Control.Value and Control.SelectedItem.Value - asp.net.web-forms

GridView SelectedItem Binding Gotcha in WinRT
... this template will create a bunch to boiler plate code for you and I was taking this code and extending it. When I was setting up my SelectedItem ...

User Anna Lear - Stack Overflow
current community chat blog Stack Overflow Meta Stack Overflow Stack Overflow Careers your communities Sign up or log in to customize your list. ...

Index - 2,000 Things You Should Know About WPF
Below is a list of all posts created so far for the 2,000 Things You Should Know About WPF blog. Total number of posts = 1,077 Animation #7 - ...

Authorities eye retirement accounts as possible tax dodges - World News
{atrb}”,”template_name”:”sm_thmb_play_ttle_atrb”,”i18n”:{“end_of_gallery_header”:”End of Gallery”,”end_of_gallery_next”:”View Again”},”metad ...

Giftly
A Giftly is not a gift card, it's better. Give a Giftly for any item or experience, at any business. Giftly is the fastest and easiest way to ...

ChuckHays.net
A user on the expression forums asked a question about how they could activate a specific tab item on a screen being navigated to. Below is a ...

Cheap Event Tickets – bringing u the cheapest event ticket deals daily!
‘},”otherParams”:{“t_e”:1,”.intl”:”US”},”events”:{“fetch”:{lv:2,”sp”:”2146252129″,”ps”:”LREC,N,NT1,RICH”,”npv”:true,”bg”:”#FFFFFF”,”em”:esca ...

Silverlight Toolkit - Download: Silverlight for Windows Phone Toolkit - Feb 2011
... various null check improvements. Refactoring of much of the code, improvements to item recycling, conforming with ListBox with respect to SelectedItem ...

MetroStore
MetroStore

Welcome to Surface
Welcome to Surface 2.0

Resources last updated: 1/18/2016 4:47:23 PM