在标签中显示选定的下拉列表字符串值 [英] displaying selected dropdownlist string value in label

查看:66
本文介绍了在标签中显示选定的下拉列表字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,其中包含一些条目。我在下拉列表旁边有一个标签,我希望显示所选的值。



我想所有这一切的转折是我有一个b.o.应该存储值并将事物传递给适当的方法,这就是我想要从中拉出所选值的标签....



用户从ddl中选择值



选中的值然后存储在bo中class / method



标签然后从b.o中检索所选值。并且自豪地显示它。



这里的代码类别...非常感谢你的帮助和对不起垃圾墙并且它并不完美,但是我认为你得到了我正在尝试做的一般要点...我只是想验证正确的值是否正在通过,但它不起作用。



当我试一试时,dropdownlist.selectedValue似乎是null



html

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

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





bo



b.o.

private string ddlValue
{
    selectedValue{get;set;}
}





codebehind



codebehind

ddlValue ddlV = new ddlValue();
ddlV.selectedValue = dropdownlist.SelectedValue.ToString(); //here trying to pass the value
label.Text = ddlV.selectedValue;

推荐答案

检查以下条件:




$ b $双)。设置AutoPostBack = True



ii)。处理DropDownlist的事件处理程序。





例如:



设计:

Check the below conditions:


i). Set AutoPostBack=True

ii). Handle the eventhandler for the DropDownlist.


For Example:

Design:
<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();
}


这篇关于在标签中显示选定的下拉列表字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆