Results 1 to 10 of 10

Thread: [CLOSED] Setting Combobox value in code behind

  1. #1
    Premium Member
    Join Date
    Dec 2008
    Posts
    199

    [CLOSED] Setting Combobox value in code behind

    I'm trying to set the selected item value for a combobox in code behind with limited success. I'm able to set some values, but not others. The product and rate card seem to be selecting properly, though the ad size is not. Please take a look and the following code sample and let me know what I'm missing. Thank you.

    Code:
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ScriptManager ID="ScriptManager1" runat="server" />   
            <ext:TextField runat="server" ID="txtItemID" Hidden="true" HideMode="Display" Text="-1"></ext:TextField>
                                  
    <ext:Store ID="store_Product" runat="server" AutoLoad="true">
        <Reader>
            <ext:ArrayReader ReaderID="ID">
                <Fields>
                    <ext:RecordField Name="ID" Type="String" />
                    <ext:RecordField Name="DropDownDisplay" Type="String" />
                </Fields>
            </ext:ArrayReader>
        </Reader>
        <Listeners>
            <Load Handler="if(this.initialized || !this.withPredefined){ #{cbo_Product}.setValue(this.getAt(0).data[#{cbo_Product}.valueField]);#{store_RateCard}.reload();};this.initialized = true;"
            Single="false" />
        </Listeners>
    </ext:Store>
      
    <ext:Store ID="store_RateCard" runat="server" AutoLoad="false" OnRefreshData="LoadRCardList">
        <Reader>
            <ext:ArrayReader ReaderID="ID">
                <Fields>
                    <ext:RecordField Name="ID" Type="String" />
                    <ext:RecordField Name="DropDownDisplay" Type="String" />
                    <ext:RecordField Name="IsNet" Type="String" />
                </Fields>
            </ext:ArrayReader>
        </Reader>
        <Listeners>
        <Load Handler="if(this.initialized || !this.withPredefined){#{cbo_RateCard}.setValue(#{cbo_RateCard}.store.getAt(0).get('ID'));#{StoreAdSizePrint}.reload();}; this.initialized = true;" />
        </Listeners>
    </ext:Store>         
    <ext:Store runat="server" 
        ID="StoreAdSizePrint" OnRefreshData="LoadAdDetails">
        <Reader>            
            <ext:ArrayReader ReaderID="ID">              
                <Fields>                
                    <ext:RecordField Name="ID" Type="String"/>
                    <ext:RecordField Name="DropDownDisplay" Type="String" />
                </Fields>            
            </ext:ArrayReader>       
        </Reader>   
        <Listeners>
            <Load Handler="if(this.initialized || !this.withPredefined){#{cboAdSize}.setValue(#{cboAdSize}.store.getAt(0).get('ID'));};this.initialized = true; " />
        </Listeners>
    </ext:Store>  
            <ext:ViewPort ID="ViewPort1" runat="server">
                <Body>
                    <ext:CenterLayout ID="CenterLayout1" runat="server">
                        <ext:Panel ID="PanelProduct" 
                            runat="server" 
                            Title="Centered Panel: 75% of container width and fit height"
                            AutoScroll="true"
                            BodyStyle="padding:20px 0;">                        
                            <CustomConfig>
                                <ext:ConfigItem Name="width" Value="75%" Mode="Value" />
                            </CustomConfig>
                           <Body>                            
                                <ext:FormLayout ID="FormLayoutCampaign" runat="server" LabelAlign="Left" LabelWidth="65" LabelSeparator="">                                                                                                                    
                                    <ext:Anchor>      
                                        <ext:ComboBox ID="cbo_Product" runat="server" 
                                            FireSelectOnLoad="true" 
                                            StoreID="store_Product"
                                            TypeAhead="true" 
                                            Mode="Local" 
                                            ForceSelection="true" 
                                            TriggerAction="All" 
                                            DisplayField="DropDownDisplay"
                                            ValueField="ID" 
                                            EmptyText="Select a Product..."
                                            FieldLabel="Product:" 
                                            Width="400">
                                            <Listeners>
                                                <Select Handler="cbo_RateCard.clearValue();store_RateCard.reload();" />
                                            </Listeners>
                                        </ext:ComboBox>
                                    </ext:Anchor>
                                    <ext:Anchor>
                                        <ext:ComboBox ID="cbo_RateCard" runat="server" 
                                            Width="400" 
                                            StoreID="store_RateCard" 
                                            TypeAhead="true"
                                            Mode="Local" 
                                            ForceSelection="True" 
                                            TriggerAction="All" 
                                            DisplayField="DropDownDisplay" 
                                            FireSelectOnload="True"
                                            ValueField="ID" 
                                            FieldLabel="Rate Card:"
                                            EmptyText="Select a Rate Card...">
                                            <Listeners>
                                                <Select Handler="#{StoreAdSizePrint}.reload();this.initialized = true;" />
                                            </Listeners>
                                        </ext:ComboBox>
                                    </ext:Anchor>                                        
                                     <ext:Anchor>
                                        <ext:ComboBox ID="cboAdSize" runat="server" StoreID="StoreAdSizePrint" FieldLabel="Ad Size" Width="200" DisplayField="DropDownDisplay" ValueField="ID" >
                                        </ext:ComboBox>                                                                    
                                    </ext:Anchor>    
                              </ext:FormLayout>
                            </Body>                        
                       </ext:Panel>
                    </ext:CenterLayout>
               </Body>
            </ext:ViewPort>        
        </div>
        </form>
    </body>
    </html>
     
    Imports Coolite.Ext.Web
    Partial Public Class _Default
        Inherits System.Web.UI.Page
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not Page.IsPostBack Then
                store_Product.CustomConfig.Add(New ConfigItem("withPredefined", "true", ParameterMode.Raw))
                store_RateCard.CustomConfig.Add(New ConfigItem("withPredefined", "true", ParameterMode.Raw))
                SetupAd()
            End If
            If Not Ext.IsAjaxRequest Then
                GetProductList()
            End If
        End Sub
        Public Sub SetupAd()
            'set the selected product and rate card for the drop down lists
            cbo_Product.SelectedItem.Value = 17
            cbo_RateCard.SelectedItem.Value = 172
            StoreAdSizePrint.CustomConfig.Add(New ConfigItem("withPredefined", "true", ParameterMode.Raw))
            cboAdSize.SelectedItem.Value = 1722
        End Sub
        Public Sub GetProductList()
            store_Product.DataSource = New Object() {New Object() {1, "Product 1"}, _
                                                  New Object() {17, "Product 17"}, _
                                                  New Object() {21, "Product 21"}}
            store_Product.DataBind()
        End Sub
        Public Sub LoadRCardList()
            'Refresh rate card data - id,name,isnet,startdate,enddate
            Select Case cbo_Product.SelectedItem.Value  'txtProductID.Text 'product
                Case 1
                    store_RateCard.DataSource = New Object() {New Object() {11, "Product 1 Rate 1", 1}, _
                                                           New Object() {12, "Product 1 Rate 2", 1}}
                Case 17
                    store_RateCard.DataSource = New Object() {New Object() {171, "Product 17 Rate 1", 0}, _
                                                           New Object() {172, "Product 17 Rate 2", 0}}
            End Select
            store_RateCard.DataBind()
        End Sub
        Public Sub LoadAdDetails() 'Ratecard selected
            Select Case cbo_RateCard.SelectedItem.Value  'txtRateCardID.Text
                Case 11
                    StoreAdSizePrint.DataSource = New Object() {New Object() {111, "Rate 11 Size 1"}, _
                                                                New Object() {112, "Rate 11 Size 2"}}
                Case 12
                    StoreAdSizePrint.DataSource = New Object() {New Object() {121, "Rate 12 Size 1"}, _
                                                                New Object() {122, "Rate 12 Size 2"}}
                Case 171
                    StoreAdSizePrint.DataSource = New Object() {New Object() {1711, "Rate 171 Size 1"}, _
                                                                New Object() {1712, "Rate 171 Size 2"}}
                Case 172
                    StoreAdSizePrint.DataSource = New Object() {New Object() {1721, "Rate 172 Size 1"}, _
                                                                New Object() {1722, "Rate 172 Size 2"}}
            End Select
            StoreAdSizePrint.DataBind()
        End Sub
    End Class
    Last edited by Daniil; Dec 17, 2010 at 1:24 PM. Reason: [CLOSED]

  2. #2
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    25,503
    Hi,

    Please clarify how we can reproduce the problem? I was unable to run the code that you provided.

    At least there is one error:

    Code:
    <ext:Store ... OnRefreshData="LoadRCardList">
    ...
    Public Sub LoadRCardList()
    The signature of OnRefreshData handler must be:
    Code:
    Delegate Sub AjaxRefreshDataEventHandler(sender As Object, e As  Coolite.Ext.Web.StoreRefreshDataEventArgs)
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  3. #3
    Premium Member
    Join Date
    Dec 2008
    Posts
    199
    I see my signature was wrong and have updated with the following:

    Code:
        Protected Sub LoadRCardList(ByVal sender As Object, ByVal e As StoreRefreshDataEventArgs)
            'Refresh rate card data - id,name,isnet,startdate,enddate
            Select Case cbo_Product.SelectedItem.Value  'txtProductID.Text 'product
                Case 1
                    store_RateCard.DataSource = New Object() {New Object() {11, "Product 1 Rate 1", 1}, _
                                                           New Object() {12, "Product 1 Rate 2", 1}}
                Case 17
                    store_RateCard.DataSource = New Object() {New Object() {171, "Product 17 Rate 1", 0}, _
                                                           New Object() {172, "Product 17 Rate 2", 0}}
            End Select
            store_RateCard.DataBind()
        End Sub
        Protected Sub LoadAdDetails(ByVal sender As Object, ByVal e As StoreRefreshDataEventArgs) 'Ratecard selected
            Select Case cbo_RateCard.SelectedItem.Value  'txtRateCardID.Text
                Case 11
                    StoreAdSizePrint.DataSource = New Object() {New Object() {111, "Rate 11 Size 1"}, _
                                                                New Object() {112, "Rate 11 Size 2"}}
                Case 12
                    StoreAdSizePrint.DataSource = New Object() {New Object() {121, "Rate 12 Size 1"}, _
                                                                New Object() {122, "Rate 12 Size 2"}}
                Case 171
                    StoreAdSizePrint.DataSource = New Object() {New Object() {1711, "Rate 171 Size 1"}, _
                                                                New Object() {1712, "Rate 171 Size 2"}}
                Case 172
                    StoreAdSizePrint.DataSource = New Object() {New Object() {1721, "Rate 172 Size 1"}, _
                                                                New Object() {1722, "Rate 172 Size 2"}}
            End Select
            StoreAdSizePrint.DataBind()
        End Sub
    Unfortunately this did not seem to solve the problem. The Ad Size combobox is still just set to the first item in the list (trying to set to second item 1722). Please let me know if you still get errors. Thank you.

  4. #4
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    25,503
    Hi,

    Well, the reason is issue that Ajax is asynchronous (as you, certainly, know).

    Briefly, this code
    Code:
    #{cboAdSize}.setValue(#{cboAdSize}.store.getAt(0).get('ID'));
    is executed after cboAdSize is rendered with initial value
    Code:
    cboAdSize.SelectedItem.Value = 1722
    I'm not sure why you use this code
    Code:
    #{cboAdSize}.setValue(#{cboAdSize}.store.getAt(0).get('ID'));
    if you want to set initial value which is not in the first record of store.

    Figuratively:
    Code:
    store.getAt(0)
    is
    Code:
    New Object() {1721, "Rate 172 Size 1"}
    So, I can suggest you the following way.

    Remove
    Code:
    cbo_RateCard.SelectedItem.Value = 172
    and
    Code:
    cboAdSize.SelectedItem.Value = 1722
    And set initial value in OnRefreshData handler
    Code:
    cboAdSize.SetValue("1722")
    or in Load's listeners
    Code:
    <ext:Store ID="store_RateCard" runat="server" AutoLoad="false" OnRefreshData="LoadRCardList">
        ...
        <Listeners>
            <Load Handler="if (!cbo_RateCard.isInitialized) { cbo_RateCard.setValue('1722'); cbo_RateCard.isInitialized = true; }" />
        </Listeners>
    </ext:Store>
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  5. #5
    Member
    Join Date
    Dec 2009
    Location
    Argentina
    Posts
    111
    hi, i don't know if this thread is related to release 3371, but with that release all my combos are getting error when loading values, in a window when are loaded again, the error i'm getting in all of them is:
    [NullReferenceException: Referencia a objeto no establecida como instancia de un objeto.]
    Ext.Net.ComboBox.LoadPostData(String postDataKey, NameValueCollection postCollection) +261
    is this right?
    thanks

  6. #6
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    25,503
    Quote Originally Posted by juane66 View Post
    hi, i don't know if this thread is related to release 3371, but with that release all my combos are getting error when loading values, in a window when are loaded again, the error i'm getting in all of them is:
    [NullReferenceException: Referencia a objeto no establecida como instancia de un objeto.]
    Ext.Net.ComboBox.LoadPostData(String postDataKey, NameValueCollection postCollection) +261
    is this right?
    thanks
    Hi,

    I'm not sure this is related. Please start a new forum thread for this issue with more details (code sample would be best).
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  7. #7
    Member
    Join Date
    Dec 2009
    Location
    Posts
    10

    error using LoadRecord(rec) where the FormPanel includes Combobox

    Quote Originally Posted by Daniil View Post
    Hi,

    I'm not sure this is related. Please start a new forum thread for this issue with more details (code sample would be best).

    After updating, I am getting the same error using LoadRecord(rec) where the FormPanel includes Combobox



    [NullReferenceException: Object reference not set to an instance of an object.]
    Ext.Net.ComboBox.LoadPostData(String postDataKey, NameValueCollection postCollection) +426
    Ext.Net.Field.System.Web.UI.IPostBackDataHandler.L oadPostData(String postDataKey, NameValueCollection postCollection) +45
    System.Web.UI.Page.ProcessPostData(NameValueCollec tion postData, Boolean fBeforeLoad) +327
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean

  8. #8
    Ext.NET - Dev Team Vladimir's Avatar
    Join Date
    Mar 2008
    Location
    Russia
    Posts
    15,158
    Hi,

    Please provide simplified test sample which demonstrates the problem
    Vladimir Shcheglov
    Ext.NET, Inc.
    Development Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  9. #9
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    25,503
    Quote Originally Posted by juane66 View Post
    hi, i don't know if this thread is related to release 3371, but with that release all my combos are getting error when loading values, in a window when are loaded again, the error i'm getting in all of them is:
    [NullReferenceException: Referencia a objeto no establecida como instancia de un objeto.]
    Ext.Net.ComboBox.LoadPostData(String postDataKey, NameValueCollection postCollection) +261
    is this right?
    thanks
    Your question is related to
    http://forums.ext.net/showthread.php...ctEvent-Issues
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  10. #10
    Member
    Join Date
    Dec 2009
    Location
    Posts
    10
    Rev. 3375 fixed the combobox issue.

    Great product. Thanks!

Similar Threads

  1. [CLOSED] DropDownField setting value from code-behind
    By kenanhancer in forum 1.x Premium Help
    Replies: 2
    Last Post: Dec 15, 2011, 7:29 AM
  2. [CLOSED] Problem setting value iconcombobox in code
    By CarWise in forum 1.x Premium Help
    Replies: 3
    Last Post: May 24, 2011, 3:04 PM
  3. Replies: 2
    Last Post: May 13, 2011, 7:06 AM
  4. [CLOSED] Setting Store OnRefreshData in code behind
    By deejayns in forum 1.x Premium Help
    Replies: 6
    Last Post: Dec 02, 2010, 3:30 PM
  5. Code behind setting Title property on portlet fails
    By netwearcdz in forum 1.x Help
    Replies: 3
    Last Post: Jan 15, 2010, 3:36 PM

Posting Permissions