在C#中使用下拉列表 [英] Using dropdown lists in C#

查看:98
本文介绍了在C#中使用下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在用C#.net4.0开发一个Web应用程序.在那我使用下拉列表.假设,如果我想访问下拉列表中的第三项并将其显示在标签中,该如何做(不使用选择的索引")?
更具体地说,我的意思是问是否可以访问数组形式的下拉列表? (即,在数组中,我们可以访问a [3]之类的特定项目)请帮助我

谢谢您.

Hi
I am developing a web application in C# .net4.0. In that i am using dropdown lists. Suppose,if i want to access 3rd item in the dropdown list and display it in a label,how can i do that(without using "selected index")?
To be more specific, i mean to ask is it possible to access a dropdown list in the form of array?? (i.e in an array, we can access a specific item like a[3]) Plz help me

Thanking you

推荐答案

您可以将Dropdownlist的元素作为Dropdwnlist.items访问.这是dropdownlist所有项目的集合.
You can access the elements of Dropdownlist as Dropdwnlist.items. this is the collection of all the items of the dropdownlist.


您可以尝试以下操作:

You can try this:

string selectedText = _DropDownList.Items[_DropDownList.SelectedIndex].Text;
string selectedValue = _DropDownList.Items[_DropDownList.SelectedIndex].Value;



或者,如果您想获取具有特定索引的项目,则可以写为



Or if you want to get the item with a particular index you can write as

string selectedText = _DropDownList.Items[3].Text;
string selectedValue = _DropDownList.Items[3].Value;




希望对您有所帮助.




Hope this helps.


您可以通过以下代码获取任何列表项的值或文本,只需更改变量名称即可.

You can get any list items value or text via the code below, just change the variable names

// sets the label to the list items Text value
nameOfLable.Text = ddlOne.Items[indexRequired].Text;

// sets the label to the list item Value 
nameOfLable.Text = ddlOne.Items[indexRequired].Value;


这篇关于在C#中使用下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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