Hi Mikael,
Here is an example. I used ObjectDataSource instead SqlDataSource but it does not matter for example
using System;
using System.Collections.Generic;
namespace Coolite.Sandbox.App_Code
{
public class TestStorage
{
public static List<object> GetSecondComboData(string firstComboValue)
{
return new List<object>
{
new {Text="Item"+firstComboValue+"_1", Value = firstComboValue+"_1"},
new {Text="Item"+firstComboValue+"_2", Value = firstComboValue+"_2"},
new {Text="Item"+firstComboValue+"_3", Value = firstComboValue+"_3"},
new {Text="Item"+firstComboValue+"_4", Value = firstComboValue+"_4"},
new {Text="Item"+firstComboValue+"_5", Value = firstComboValue+"_5"}
};
}
public static List<object> GetFirstComboData()
{
return new List<object>
{
new {Text="Item1", Value = "1"},
new {Text="Item2", Value = "2"},
new {Text="Item3", Value = "3"},
new {Text="Item4", Value = "4"},
new {Text="Item5", Value = "5"}
};
}
}
}
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Collections.Generic"%>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if(!Ext.IsAjaxRequest)
{
dsFirstCombo.DataBind();
if(!string.IsNullOrEmpty(this.FirstCombo.SelectedItem.Value))
{
SecondComboODS.SelectParameters["firstComboValue"].DefaultValue = this.FirstCombo.SelectedItem.Value;
dsSecondCombo.DataBind();
}
}
}
protected void SecondComboRefresh(object sender, StoreRefreshDataEventArgs e)
{
SecondComboODS.SelectParameters["firstComboValue"].DefaultValue = this.FirstCombo.SelectedItem.Value;
dsSecondCombo.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server" />
<asp:ObjectDataSource ID="FirstComboODS" runat="server"
SelectMethod="GetFirstComboData"
TypeName="Coolite.Sandbox.App_Code.TestStorage">
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="SecondComboODS" runat="server"
SelectMethod="GetSecondComboData"
TypeName="Coolite.Sandbox.App_Code.TestStorage">
<SelectParameters>
<asp:Parameter Name="firstComboValue" DefaultValue="" />
</SelectParameters>
</asp:ObjectDataSource>
<ext:Store ID="dsFirstCombo" runat="server" DataSourceID="FirstComboODS">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="Text"></ext:RecordField>
<ext:RecordField Name="Value"></ext:RecordField>
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
<ext:Store ID="dsSecondCombo" runat="server" DataSourceID="SecondComboODS" OnRefreshData="SecondComboRefresh">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="Text"></ext:RecordField>
<ext:RecordField Name="Value"></ext:RecordField>
</Fields>
</ext:JsonReader>
</Reader>
<Listeners>
<Load Handler="#{SecondCombo}.setValue(this.getAt(0).get(#{SecondCombo}.valueField));" />
</Listeners>
</ext:Store>
<ext:ComboBox ID="FirstCombo" runat="server" StoreID="dsFirstCombo" DisplayField="Text" ValueField="Value">
<SelectedItem Value="3" />
<Listeners>
<Select Handler="#{dsSecondCombo}.reload();" />
</Listeners>
</ext:ComboBox>
<ext:ComboBox ID="SecondCombo" runat="server" StoreID="dsSecondCombo" DisplayField="Text" ValueField="Value">
</ext:ComboBox>
</form>
</body>
</html>