如何根据所选值获取下拉列表文本值。 [英] How to get dropdownlist text value on the basis of selected value.

查看:68
本文介绍了如何根据所选值获取下拉列表文本值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含多个数据的下拉列表。如果我的结果为0,则打印UK。如果为1则打印US。现在我想要一个基于所选值的结果作为文本(国家名称)的查询。

< asp:ListItem Value =   0 >美国< /   asp:ListItem  >  
< asp:ListItem Value = 1> ; UK < / asp:ListItem >
< asp:ListItem Value = 2> UAE < / asp:ListItem >



我怎样才能使我尝试这么多查询,但没有达到解决方案。如果有任何机构有一个想法,请与我分享。

解决方案

您可以将ListItem添加为选定值作为选定值
< blockquote>dropDownListId.SelectedItem.Text为您提供美国,英国或阿联酋


嘿我已经解决了它,这是一个小任务。 

< pre lang = c# >
string s = DropDownList1.SelectedValue;

ListItem li = new ListItem();
li = DropDownList1.Items.FindByValue(s);
Label1.Text = li.Text;


Suppose I have a dropdownlist with several data. If My result comes as 0, then it print "UK". If 1 then it print "US". Now i want a query which result as text (country name) on the basis of selected value.

<asp:ListItem Value="0">US</asp:ListItem>
<asp:ListItem Value="1">UK</asp:ListItem>
<asp:ListItem Value="2">UAE</asp:ListItem>


How can i make it possible I try so many query but doesn't reach to the solution. If any body have an idea kindly share to me.

解决方案

you can add a ListItem as "selected value" as selected value


"dropDownListId.SelectedItem.Text" gives you US, UK or UAE


Hey I have resolved it, Its a minor task. 

<pre lang="c#">
        string s = DropDownList1.SelectedValue;
   
        ListItem li = new ListItem();
        li = DropDownList1.Items.FindByValue(s);
        Label1.Text = li.Text;


这篇关于如何根据所选值获取下拉列表文本值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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