我有一个带有多选项的组合框,我想设置一个多值 codebehind,这是我的商店:
<ext:Store ID="StoreT" runat="server" PageSize="10">
<Model>
<ext:Model ID="Model3" runat="server">
<Fields>
<ext:ModelField Name="name" />
<ext:ModelField Name="code" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
<ext:ComboBox ID="ComboBoxT" MultiSelect="true" StoreID="StoreT" DisplayField="name" ValueField="code">
</ext:ComboBox>
我想传递给同时选择的setValues多个代码。
答案 0 :(得分:1)
请使用ComboBox的SelectedItems。
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.ComboBox1.GetStore();
store.DataSource = new object[]
{
new object[] { "1", "Item 1" },
new object[] { "2", "Item 2" },
new object[] { "3", "Item 3" },
new object[] { "4", "Item 4" }
};
}
}
protected void SetValues(object sender, DirectEventArgs e)
{
this.ComboBox1.SelectedItems.Clear();
this.ComboBox1.SelectedItems.Add(new Ext.Net.ListItem { Value = "2" });
this.ComboBox1.SelectedItems.Add(new Ext.Net.ListItem { Value = "4" });
this.ComboBox1.UpdateSelectedItems();
}
</script>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:Button runat="server" Text="Set 2 and 4" OnDirectClick="SetValues" />
<ext:ComboBox
ID="ComboBox1"
runat="server"
DisplayField="text"
ValueField="value"
MultiSelect="true">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="value" />
<ext:ModelField Name="text" />
</Fields>
</ext:Model>
</Model>
<Reader>
<ext:ArrayReader />
</Reader>
</ext:Store>
</Store>
<SelectedItems>
<ext:ListItem Value="1" />
<ext:ListItem Value="3" />
</SelectedItems>
</ext:ComboBox>
</form>
</body>
</html>