手动添加项到ComboBox [英] Manually Add Items to ComboBox
本文介绍了手动添加项到ComboBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在看Devexpress文档,了解如何手动将项目列表添加到组合框中。
I've been looking at devexpress documentation on how to manually add a list of items to a combo box.
任何人都可以帮助我。 p>
Can anybody help me with this please.
dx:ASPxComboBox ID="ddl_time" runat="server" ValueType="System.String">
<Columns>
<dx:ListBoxColumn Caption="First Name" FieldName="FirstName" Name="firstname"/>
</Columns>
</dx:ASPxComboBox>
这是我可以找到的。
我不想从数据源中手动添加项目。
this is all I can find. I don't want to do it from a datasource just add the items manually.
推荐答案
选项1
如果您使用下面的代码,在代码后面,您可以看到结果。
Option 1
If you use the code below, in your code behind, you can see the result.
protected void Page_Load(object sender, EventArgs e)
{
ddl_time.DataSource = GetDataSource();
ddl_time.DataBind();
}
private DataTable GetDataSource()
{
//datatable definiton
var dtSource = new DataTable();
dtSource.Columns.Add("Id", typeof(int));
dtSource.Columns.Add("FirstName", typeof(string));
//fill sample rows
dtSource.Rows.Add(1, "Item One");
dtSource.Rows.Add(2, "Item Two");
dtSource.Rows.Add(3, "Item Three");
dtSource.Rows.Add(435438792, "Item Drink");
return dtSource;
}
选项2
如果您使用这种方式,您应该删除列
标签定义。
protected void Page_Load(object sender, EventArgs e)
{
var item = new ListEditItem("Item One", 1);
ddl_time.Items.Add(item);
item = new ListEditItem("Item Two", 2);
ddl_time.Items.Add(item);
item = new ListEditItem("Item Three", 3);
ddl_time.Items.Add(item);
item = new ListEditItem("Item Drink", 435438792);
ddl_time.Items.Add(item);
ddl_time.SelectedIndex = 0;
}
选项3
Option 3
<dx:ASPxComboBox ID="ddl_time" runat="server" SelectedIndex="0">
<Items>
<dx:ListEditItem Selected="True" Text="Item One" Value="1"></dx:ListEditItem>
<dx:ListEditItem Text="Item Two" Value="2"></dx:ListEditItem>
<dx:ListEditItem Text="Item Three" Value="3"></dx:ListEditItem>
<dx:ListEditItem Text="Item Drink" Value="435438792"></dx:ListEditItem>
</Items>
</dx:ASPxComboBox>
要在编辑器中添加项目:
To add items in editor:
这篇关于手动添加项到ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文