Jul 16, 2013, 6:59 PM
[CLOSED] How to select existing item in ComboBox on the server?
Hi,
It's probably a very basic question. I need to select an existing list item on the server. The code below doesn't work. Could you please suggest the right approach or point out what's wrong?
It's probably a very basic question. I need to select an existing list item on the server. The code below doesn't work. Could you please suggest the right approach or point out what's wrong?
<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
var list = new List<object>
{
new {Text = "Text3", Value = 3},
new {Text = "Text4", Value = 4},
new {Text = "Text5", Value = 5}
};
this.Store1.DataSource = list;
this.Store1.DataBind();
// This call doesn't work
ComboBox1.SelectedItems.Add(new Ext.Net.ListItem { Value = "4" });
// Item reference resolves to null so this call doesn't work
/*
var item = ComboBox1.Items.Where(it => it.Value.Equals("4")).FirstOrDefault();
if (item != null)
{
ComboBox1.SelectedItems.Add(item);
}
*/
// This call doesn't work either
//ComboBox1.Select(1);
}
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Ext.Net 2.x</title>
<ext:ResourcePlaceHolder ID="ResourcePlaceHolder1" runat="server" Mode="Script" />
<ext:ResourcePlaceHolder ID="ResourcePlaceHolder2" runat="server" Mode="Style" />
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server">
</ext:ResourceManager>
<ext:Viewport runat="server" Layout="FitLayout">
<Items>
<ext:Panel runat="server">
<Items>
<ext:ComboBox ID="ComboBox1" runat="server" DisplayField="Text" ValueField="Value"
FieldLabel="Select" QueryMode="Local">
<Store>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model ID="Model1" runat="server" IDProperty="Value">
<Fields>
<ext:ModelField Name="Text" />
<ext:ModelField Name="Value" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</Items>
</ext:Panel>
</Items>
</ext:Viewport>
</form>
</body>
</html>
Last edited by Daniil; Jul 17, 2013 at 4:24 AM.
Reason: [CLOSED]