本文介绍了在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

推荐答案


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.


// 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#中使用下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 20:59