Using declarative databinding with LoadOnDemand

Thread is closed for posting
10 posts, 0 answers
  1. A9E74E7C-52FA-4440-8D67-C26A0770B01B
    A9E74E7C-52FA-4440-8D67-C26A0770B01B avatar
    16 posts
    Member since:
    May 2004

    Posted 05 Apr 2007 Link to this post

    Requirements

    To convert code
    from posted project(s)
    Telerik online converter
    RadControl version RadComboBox v2.x or Telerik.Web.UI v2007.3 1425
    .NET version

    2.0
    Visual Studio version

    VS.NET 2005
    programming language

    C#
    browser support

    all browsers supported by RadComboBox




    PROJECT DESCRIPTION
    Data binding RadComboBox to a declarative datasource control using its DataSourceID property is an easy task. It is relatively simple to set up dependent combo boxes that request subsets of a dataset using a data source ControlParameter that points to another combo box's SelectedValue property:

    <asp:ObjectDataSource ID="citiesDataSource" runat="server" OldValuesParameterFormatString="original_{0}" 
        SelectMethod="GetCities" TypeName="ComboDataLayer"
        <SelectParameters> 
            <asp:ControlParameter ControlID="RadComboBox2" DefaultValue="1" Name="countryID" PropertyName="SelectedValue" 
                Type="String" /> 
        </SelectParameters> 
    </asp:ObjectDataSource> 

    Unfortunately this is very hard to do when the control has its load on demand feature turned on. RadComboBox sends Ajax requests to the server and keeps them extremely lightweight -- the data sent contains only the control id and the text that has been typed so far. The SelectedValue property is not populated and we cannot use a ControlParameter.

    We can work around that by creating a custom data source parameter class and add our data retrieval logic there. This way we can set up our data source like this:

    <asp:ObjectDataSource ID="countriesDataSource" runat="server" OldValuesParameterFormatString="original_{0}" 
        SelectMethod="GetCountries" TypeName="ComboDataLayer"
        <SelectParameters> 
            <telerik:AjaxComboValueParameter AjaxComboID="RadComboBox2" DefaultValue="1" Name="continentID" 
                Type="String" /> 
        </SelectParameters> 
    </asp:ObjectDataSource> 

    Note the AjaxComboID property. We use it to detect if the current Ajax request has been initiated by our target combo box.

    We have to set the combo box's DataSourceID and data bind it in the ItemsRequested event handler:

        protected void RadComboBox2_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) 
        { 
            RadComboBox2.DataSourceID = "countriesDataSource"
     
            RadComboBox2.DataBind(); 
        } 

    And finally the AjaxComboValueParameter code:

        /// <summary> 
        /// An AjaxComboValueParameter instance will return the currently typed value of  
        /// the combobox that has initiated the Ajax request. In cases where we are not inside an Ajax request 
        /// or the request has been initiated by another combo, we return the default value. 
        /// </summary> 
        public class AjaxComboValueParameter : Parameter 
        { 
            public AjaxComboValueParameter() 
            { 
     
            } 
     
            /// <summary> 
            /// The server ID of the combo that will initiate the Ajax requests. 
            /// </summary> 
            public string AjaxComboID 
            {  
                get 
                { 
                    return ViewState["AjaxComboID"as string ?? string.Empty; 
                } 
                set 
                { 
                    ViewState["AjaxComboID"] = value; 
                } 
            } 
     
            protected override object Evaluate(HttpContext context, Control control) 
            { 
                string ajaxInitiator = context.Request.QueryString["rcbServerID"]; 
                if (!string.IsNullOrEmpty(ajaxInitiator)) 
                { 
                    if (ajaxInitiator.Contains(AjaxComboID)) 
                    { 
                        string comboValue = context.Request.QueryString["text"]; 
                        return comboValue; 
                    } 
                    else 
                    { 
                        return DefaultValue; 
                    } 
                } 
                else 
                { 
                    return base.Evaluate(context, control); 
                } 
            } 
     
     
        } 



    PROJECT DESCRIPTION
    Same as the above, without the highlighted parts. Here, RadComboBox will be automatically bound to its corresponding data source which is declared in the ASPX.
  2. E87DB616-9A41-49EC-B7C3-24614E2E04C2
    E87DB616-9A41-49EC-B7C3-24614E2E04C2 avatar
    14 posts
    Member since:
    Feb 2008

    Posted 30 Apr 2008 Link to this post

    In my senario, my combobox is an item list which consisits of a radtreeview which is inside formview in edit mode.
    treeview is populated on serversidecallback. onclientnode changing of treeview, i set the value of combobox by
    combobox.set_value(node.get_value());
    which works fine by the javascript.
    but it tends to work only in client side.
    when i click the update button in the formview, it always assumes that the combobx value is 0, set_value() doesn't tend to work in the serveside?
  3. 06D55E1C-D060-47BE-B6A7-5641D8582E98
    06D55E1C-D060-47BE-B6A7-5641D8582E98 avatar
    39 posts
    Member since:
    Jun 2012

    Posted 21 Jul 2010 Link to this post

    how about this in a formview with declarative data binding to a guid key field? that is what I think many people are doing now and I cannot find an adequate example for this
  4. 11003FA9-64D8-4477-91C3-84B3F7E03DDE
    11003FA9-64D8-4477-91C3-84B3F7E03DDE avatar
    5044 posts
    Member since:
    Sep 2017

    Posted 22 Jul 2010 Link to this post

    Hello EJ,

    Could you please follow this forum thread? Your question has been already answered there.

    Greetings,
    Yana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. 34C27C6F-C6E2-4B66-8061-D94654A80F9F
    34C27C6F-C6E2-4B66-8061-D94654A80F9F avatar
    6 posts
    Member since:
    Nov 2006

    Posted 16 Feb 2012 Link to this post

    I can get this to work on a form (aspx) or control (ascx), but I still cannot figure out how to get this to work in an RadGrid Edit Form Template. 

    If you put the declarative data source control OUTSIDE the <FormTemplate> tag, the page complains that it "Could not find control "referencedControl" in ControlParameter "referencedControlParameter".

    If you put the declarative data source control INSIDE the <FormTemplate> tag, the page complains that "The DataSourceID of "referencedControl" must be the ID of a control of type IDataSource. A control with ID "referenced data source control" could not be found.

    I can't even get this to wire up in the code-behind, has anyone figured out how to get this to work?

    Thanks,
    Jim
  6. 2636E19F-ED28-4F48-9429-307839A66131
    2636E19F-ED28-4F48-9429-307839A66131 avatar
    657 posts
    Member since:
    Sep 2012

    Posted 20 Feb 2012 Link to this post

    Hi James,

    If you are using our ASP.NET AJAX controls, you could refer to our online demo which demonstrates loaded on demand RadComboBox placed inside an edit item template of RadGrid:
    [http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/comboingrid/defaultcs.aspx?product=combobox].

    Greetings,
    Ivana
    the Telerik team

    Consider using RadControls for ASP.NET AJAX (built on top of the ASP.NET AJAX framework) as a replacement for the Telerik ASP.NET Classic controls, See the product support lifecycle here.

  7. 34C27C6F-C6E2-4B66-8061-D94654A80F9F
    34C27C6F-C6E2-4B66-8061-D94654A80F9F avatar
    6 posts
    Member since:
    Nov 2006

    Posted 21 Feb 2012 Link to this post

    Ivana, thank you for your response. 
    However - my problem is in hooking up the combo box in an edit FORM template of the RadGrid, not an edit ITEM template (which is why I talked about the <FormTemplate> tag).
    I've searched your site but can find no mention of how to do that - is it simply not supported?
  8. 2636E19F-ED28-4F48-9429-307839A66131
    2636E19F-ED28-4F48-9429-307839A66131 avatar
    657 posts
    Member since:
    Sep 2012

    Posted 23 Feb 2012 Link to this post

    Hi James,

    If the problem you experience if related to the following one: Bind a Load On Demand RadComboBox inside an EditItemTemplate of RadGrid, I would recommend to continue our conversation in there.

    In the aforementioned thread, I have provided a link to a CL article which you can use for reference -- it contains a related RadComboBoxes scenario implemented inside a FormTemplate of a RadGrid:
    ...
    <EditFormSettings EditFormType="Template">
        <FormTemplate>
            ...
        </FormTemplate>
    </EditFormSettings>
    ...

    If this is not your scenario -- I would suggest to open a support ticket and provide us with a sample project of your attempts. This way we will troubleshoot the problem locally and provide you with a solution for it.

    Greetings,
    Ivana
    the Telerik team

    Consider using RadControls for ASP.NET AJAX (built on top of the ASP.NET AJAX framework) as a replacement for the Telerik ASP.NET Classic controls, See the product support lifecycle here.

  9. 3DC4FC47-ABC4-4B04-80C7-08B254EE135F
    3DC4FC47-ABC4-4B04-80C7-08B254EE135F avatar
    1 posts
    Member since:
    Sep 2012

    Posted 26 Jan 2015 in reply to 11003FA9-64D8-4477-91C3-84B3F7E03DDE Link to this post

    Link not working 'this forum thread'.  
  10. 26B6D8A3-7747-4BAC-83DF-B093F8126EA1
    26B6D8A3-7747-4BAC-83DF-B093F8126EA1 avatar
    2062 posts
    Member since:
    Dec 2019

    Posted 28 Jan 2015 Link to this post

    Hi,

    Indeed the link is broken. Please refer to RadComboBox - LoadOnDemand and Setting Initital Value/Text forum thread.

    Regards,
    Boyan Dimitrov
    Telerik
     

    Consider using RadControls for ASP.NET AJAX (built on top of the ASP.NET AJAX framework) as a replacement for the Telerik ASP.NET Classic controls, See the product support lifecycle here.

     
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.