Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a dropdownlist with a few entries in it. i have a label next to the dropdownlist that i'd like to have display the selected value.

i guess the twist in all of this is that i have a b.o. which is supposed to store the values and pass things on to the appropriate method and this is where i'd like the label to pull the selected value from so....

user selects value from ddl

selected value is then stored in the b.o. class/method

the label then retrieves the selected value from the b.o. and displays it proudly.

here's the code sort of...thank you very much for the help and sorry for the wall of junk and it's not perfect, but i think you get the general gist of what i'm trying to do...i just want to make verify that the right values are passing through, but it's not working.

when i try this out, the dropdownlist.selectedValue seems to be null

html
HTML
<div>
    <dropdownlist>
        <listitem VALUE = 'A'> A </>
        <listitem VALUE = 'B'> B </>
        <listitem VALUE = 'C'> C </>
    </dropdownlist>
    <label />
</div>


b.o.
C#
private string ddlValue
{
    selectedValue{get;set;}
}


codebehind
C#
ddlValue ddlV = new ddlValue();
ddlV.selectedValue = dropdownlist.SelectedValue.ToString(); //here trying to pass the value
label.Text = ddlV.selectedValue;
Posted
Comments
BillWoodruff 19-Dec-13 13:34pm    
Where's the EventHandler for the DropDown selection change that will invoke the code ? 'ddlValue appears to be a property, why are you using the 'new operator as if you were creating an instance of a Class ?
bowlturner 19-Dec-13 13:49pm    
not only that why doesn't the dropdownlist have a name? I'm pretty sure this ddlV.selectedValue = dropdownlist.SelectedValue.ToString(); won't work with out an actual name.

1 solution

Check the below conditions:


i). Set AutoPostBack=True

ii). Handle the eventhandler for the DropDownlist.


For Example:

Design:
ASP.NET
<asp:dropdownlist runat="server" id="ddlTest" autopostback="True" onselectindexchanged="ddlTest_IndexChanged" xmlns:asp="#unknown" />

<asp:label runat="server" id="lblTest" xmlns:asp="#unknown" />


Code Behind:
protected void ddlTest_IndexChanged(Object sender, EventArgs e)
{
    lblTest.Text=ddlTest.SelectedValue.ToString();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900