简体   繁体   English

从dropDownlist返回字符串

[英]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. 我遇到了一个非常基本的问题,我试图在选定索引更改时从DropDownList的选定值返回一个字符串值,但是由于某种或其他原因却没有发生。

 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. 当我尝试向数据库添加名称时,出现NullReferenceException。

Advice perhaps 建议也许

i guess you are talking about the asp.net dropdown list control 我猜你在谈论asp.net下拉列表控件

use drpMinisters.Text to get the selected value (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.text.aspx) 使用drpMinisters.Text获得选定的值(http://msdn.microsoft.com/zh-cn/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; 如果您使用的是ASP .net,则可以尝试类似的操作。var ddValue = document.getElementById(“您的下拉列表项”) .options [document.getElementById(“您的下拉列表项”) .selectedIndex ] .text; I was facing same problem it solved my problem with 我遇到了同样的问题,它解决了我的问题

"NullReferenceException" “ NullReferenceException”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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