[CLOSED] Linked combos with SQL datasource

  1. #1

    [CLOSED] Linked combos with SQL datasource



    Hi
    How do I do the linked combos example you showed me with a SQL Datasource? I have a store that looks something like this like this:

        <asp:SqlDataSource ID="SqlCombo2" runat="server" OnRefreshData = "??" ConnectionString=""  />  
        <ext:Store ID="StoreCombo2" runat="server" DataSourceID="SqlCombo2">
            <Reader>            
                <ext:JsonReader ReaderID="Combo2Id">
                    <Fields>
                        <ext:RecordField Name="Combo2Id" Type="String" />                        
                        <ext:RecordField Name="Combo2Name" Type="String" />                    
                    </Fields>
                </ext:JsonReader>
            </Reader>
          
        </ext:Store>
    What should the refreshdata be set to?

    /Mikael
  2. #2

    RE: [CLOSED] Linked combos with SQL datasource

    Hi,

    OnRefreshData is Store event handler (not SqlDataSource) . In this handler you need rebind Store


    <ext:Store ID="Store1" runat="server"
    DataSourceID="SqlCombo2"
    OnRefreshData="Store1_RefershData">


    protected void Store1_RefershData(object sender, StoreRefreshDataEventArgs e)
    {
    this.Store1.DataBind();
    }

  3. #3

    RE: [CLOSED] Linked combos with SQL datasource

    Hi I dont get it to work, and I dont understand how this is suppose to work, where does combo2 get the value from combo1 to get the right data? I want the data in the second combo to be preselected when the page loads with the right data relative to Combo1

    Thanks Mikael
    
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlCombo1.SelectCommand = "Select * from datatable";
            SqlCombo2.SelectCommand = "Select * from datatable where id=cbComboBox1.SelectedItem.value";
    
        }
    
        protected void StoreResorts_RefershData(object sender, StoreRefreshDataEventArgs e)
        {
            this.StoreResorts.DataBind();
        }
    
    
        <asp:SqlDataSource ID="SqlCombo1" runat="server"  ConnectionString=""  />  
        <ext:Store ID="StoreCombo1" runat="server" DataSourceID="SqlCombo1">
            <Reader>            
                <ext:JsonReader ReaderID="Combo1Id">
                    <Fields>
                        <ext:RecordField Name="Combo1Id" Type="String" />                        
                        <ext:RecordField Name="Combo1Name" Type="String" />                    
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <Listeners>
                <Load Handler="#{StoreCombo2}.reload();" />
            </Listeners>       
        </ext:Store>          
              
        <asp:SqlDataSource ID="SqlCombo2" runat="server"  ConnectionString=""  />  
        <ext:Store ID="StoreCombo2" runat="server" DataSourceID="SqlCombo2" OnRefreshData="StoreCombo2_RefershData">
            <Reader>            
                <ext:JsonReader ReaderID="Combo2Id">
                    <Fields>
                        <ext:RecordField Name="Combo2Id" Type="String" />                        
                        <ext:RecordField Name="Combo2Name" Type="String" />                    
                    </Fields>
                </ext:JsonReader>
            </Reader>      
        </ext:Store>
  4. #4

    RE: [CLOSED] Linked combos with SQL datasource

    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>
  5. #5

    RE: [CLOSED] Linked combos with SQL datasource

    Thank you, this works great!

    /Mikael

Similar Threads

  1. Ajax linked combos
    By ddolan in forum 1.x Help
    Replies: 0
    Last Post: Feb 17, 2011, 8:30 PM
  2. Replies: 0
    Last Post: Apr 01, 2010, 6:51 AM
  3. The example Linked combos in grid.
    By FreddeM in forum Examples and Extras
    Replies: 1
    Last Post: Jan 04, 2010, 2:41 PM
  4. Linked Combos - Set selected values
    By Tbaseflug in forum 1.x Help
    Replies: 0
    Last Post: Jul 29, 2009, 11:04 AM
  5. Linked Combos in Grid Version 0.7
    By eguerrap in forum 1.x Help
    Replies: 0
    Last Post: Jan 27, 2009, 3:19 PM

Posting Permissions