如何将文本值添加到组合框 [英] How to add textual values to a Combo Box

查看:204
本文介绍了如何将文本值添加到组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在后面的代码中向ASP.Net中的ComboBox添加文本值。

有谁知道我怎么做到这一点?

I want to add textual values to a ComboBox in ASP.Net in the code behind.
Does anyone know how I can achieve this?

推荐答案

您可以通过两种方式完成:

1.您可以更改数据源并重新绑定DropDownList。

2.在DropDownList中插入项目TextBox的TerxtChanged事件(AutoPostBack属性应该为true,以便文本框触发服务器端事件)。试试这个:

You can do it in two ways:
1. Either you can alter your datasource and rebind the DropDownList.
2. Insert the items in DropDownList in TerxtChanged event of your TextBox(AutoPostBack property should be true for textbox to fire server side event). Try this:
drpList.Items.Insert(0, new ListItem(TextBox1.Text.Trim(), TextBox1.Text.Trim()));







--Amit




--Amit


使用

Use
//Code here to populate DropDownList
DropDownListID.Items.Insert(0, new ListItem("text", "value")
///
///  0 is the index at which you want to insert the text. Text means the text
///  which is shown to the user and value is a unique value (enum or a number) 
///  which can be used in the code-behind to uniquely identify a dropdown item.







我希望这能帮助你,

使用下面的有疑问或评论?按钮要求进一步澄清。



欢呼,

Marco Bertschi




I hope this helped you,
use the "Have a question or a comment?" button below to ask for further clarification.

cheers,
Marco Bertschi


这篇关于如何将文本值添加到组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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