如何在selectedindexchanged事件中使用下拉列表选定值 [英] how to use dropdown selected value inside its selectedindexchanged event

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

问题描述

认为这个问题几乎总结一下。



我的要求很简单,

1)填写了数据库的下拉列表。

2)根据下拉列表中的选定值,我必须显示一个表格。

即使表格可以单独显示一些下拉选项。



现在,它看起来很简单,但是我在过去2个小时就打破了我的头脑。



我有什么完成了,我已经尝试检查下拉选择索引中的dropdown.selectedvalue.text =something已更改,但它不起作用。



我知道我丢失了一些东西这里基本的。



请指导我走正确的道路。



谢谢。

Think the question pretty much sums it up.

My requirement is simple,
1)Have populated a dropdown from database.
2) Based on the selected value in dropdown, I have to show a table.
ie make the table visible for some drop down selections alone.

Now, it looks pretty simple, but Iam breaking my head for the past 2 hours on this.

What I have done is, I have tried checking the dropdown.selectedvalue.text="something" inside the dropdown selected index changed, but it doesnt work.

I know Iam missing something basic here.

Pls guide me in the right path.

Thanks.

推荐答案

尝试 DropDownList.SelectedIndex属性 [ ^ ] - 应该是一个盯着选定的指南更改。
Try DropDownList.SelectedIndex Property [^] - should be a guide to get stared with selected change.


下面的代码需要写在下拉列表的selectedindexchanged事件中。

The below code needs to be written in the selectedindexchanged event of the dropdown.
ComboBox cmb = (ComboBox)sender;
if (cmb.SelectedValue.ToString().Equals("Something")
{
    //Do Something
}





希望这会有所帮助。



Hope this helps.


基于这个事实TS提到填充数据库的下拉列表,SelectedValue实际上不太可能是一个字符串。

很可能,ValueMember绑定到数据库中记录的Id,DisplayMember必然会一些说明。

Based on the fact that the TS mentioned populating the dropdown from the database, it's very unlikely that SelectedValue is actually a string.
More than likely, ValueMember is bound to the Id of the record in the database, DisplayMember is bound to some Description.
object val = ((ComboBox)sender).SelectedValue; // returns the Id
string txt = ((ComboBox)sender).SelectedText; // returns the text visible on the screen for the selected item
object item = ((ComboBox)sender).SelectedItem; // returns the entire object from the datasource you have bound to the combobox



根据您的需要,使用其中任何一个来检索/显示更多数据。


Depending on your needs, use any of these to retrieve/show further data.


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

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