简体   繁体   中英

Returning string from a dropDownlist

I have what is a very elementary problem I realize, I am trying to return a string value from a selected value of a DropDownList upon selected index change but for some or other reason it is not happening.

 protected void drpMinisters_SelectedIndexChanged(object sender, EventArgs e)
{
    name = drpMinisters.SelectedValue;
    LabMessage.Text = name;

}

When I try to add name to a database I get a NullReferenceException.

Advice perhaps

i guess you are talking about the asp.net dropdown list control

use drpMinisters.Text to get the selected value (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.text.aspx)

You can try something like this if you are using ASP .net var ddValue= document.getElementById("your Drop Down List Item").options[document.getElementById("your Drop Down List Item").selectedIndex].text; I was facing same problem it solved my problem with

"NullReferenceException"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM