Aug 14, 2013, 2:26 PM
[CLOSED] How to select a ComboBox option in Direct Method?
Hi,
I'm trying to port some existing 1.x code and curious how to make a ComboBox selection on the server in DirectMethod context. Please consider the code sample below and advise what adjustments are needed.
I'm trying to port some existing 1.x code and curious how to make a ComboBox selection on the server in DirectMethod context. Please consider the code sample below and advise what adjustments are needed.
<%@ 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 {CountryName = "Canada", CountryID = 1},
new {CountryName = "Great Britain", CountryID = 2},
new {CountryName = "United States", CountryID = 3}
};
this.Store1.DataSource = list;
this.Store1.DataBind();
ComboBox1.SelectedItems.Add(new Ext.Net.ListItem(2));
}
}
[DirectMethod]
public void SelectCountry()
{
ComboBox1.SelectedItems.Clear();
ComboBox1.SelectedItems.Add(new Ext.Net.ListItem(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>
<script type="text/javascript">
var selectCountry = function () {
X.SelectCountry();
};
</script>
<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" DirectMethodNamespace="X">
</ext:ResourceManager>
<ext:Viewport runat="server" Layout="FitLayout">
<Items>
<ext:Panel runat="server">
<Items>
<ext:ComboBox ID="ComboBox1" runat="server" DisplayField="CountryName" ValueField="CountryID"
TypeAhead="true" Editable="true" MinChars="2" SelectOnFocus="true" EmptyText="Select Country..."
FieldLabel="Select Country" QueryMode="Local">
<Store>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model ID="Model1" runat="server" IDProperty="CountryID">
<Fields>
<ext:ModelField Name="CountryName" />
<ext:ModelField Name="CountryID" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
<ext:Button runat="server" Text="Select Country">
<Listeners>
<Click Handler="selectCountry();">
</Click>
</Listeners>
</ext:Button>
</Items>
</ext:Panel>
</Items>
</ext:Viewport>
</form>
</body>
</html>
Last edited by Daniil; Aug 14, 2013 at 5:46 PM.
Reason: [CLOSED]