RCB with datasource returning empty items

18 posts, 1 answers
  1. Casper
    Casper avatar
    24 posts
    Member since:
    Mar 2015

    Posted 30 Apr 2015 Link to this post

    Hi,

    I have a problem with my comboBoxes on the client side of my application. When I call [ComboBox].get_items() I get a collection of items as expected, but the items are empty. What I find odd is that if I navigate to the itemData property i can see that the value of the items are correct even though there is no text property.

    The combobox is defined as follows:

    <telerik:RadComboBox ID="projectComboBox"
                            runat="server"
                            DataSourceID="ProjectSqlSource"
                            DataValueField="project_id"
                            DataTextField="Name" />
    Where the SQL source contains only the project_id and Name columns. On the page itself, the combobox nicely shows all of the projects. It is possible to retrieve the first text and value of the RCB, but it doesn't seem to change the selected item. It might be important to note that I've twp other RCBs configured in the same way and I can easily access the data in the code behind when it is posted back to the server.

     Hope you are able to help

     

    Regards

    Casper

  2. Casper
    Casper avatar
    24 posts
    Member since:
    Mar 2015

    Posted 30 Apr 2015 Link to this post

     It might be important to note that I've twp other RCBs configured in the same way and I can easily access the data in the code behind when it is posted back to the server

    Forgot to mention that I tested to see if I had the same problem on this page and I do, I just didn't notice this because the data from those RCBs is processed on the server.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 05 May 2015 Link to this post

    Hi Casper,

    You are using document.getElementById. This will return HTML element, but you need combobox object. Replace it with $find

    function newPlanShow(oWnd)
       var lol = $find("projectComboBox");
       var items = lol.get_items();
    }

    I hope this helps

    Regards,
    Hristo Valyavicharski
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  5. Casper
    Casper avatar
    24 posts
    Member since:
    Mar 2015

    Posted 05 May 2015 in reply to Hristo Valyavicharski Link to this post

    I'm sorry should've mentioned that I started by using $find, but it returns null 
  6. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 08 May 2015 Link to this post

    If $find doesn't return object probably the ID is different, because it is nested inside other control. Try this:

    var lol = $find("<%= RadComboBoxProject.ClientID %>");
    var items = lol.get_items();

    Regards,
    Hristo Valyavicharski
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  7. Casper
    Casper avatar
    24 posts
    Member since:
    Mar 2015

    Posted 08 May 2015 in reply to Hristo Valyavicharski Link to this post

    I still returns null.

    I think I read somewhere that you can use the control property of the HTML object, which is why I tried that instead. 
    Do we have other options?

  8. Casper
    Casper avatar
    24 posts
    Member since:
    Mar 2015

    Posted 08 May 2015 in reply to Hristo Valyavicharski Link to this post

    It is in a standard HTML table, it still returns null though.

    <table>
        <tr>
            <td>
                <telerik:RadComboBox runat="server" ID="RadComboBoxProject" OnSelectedIndexChanged="OnProjectTextChanged"
                    AutoPostBack="True" ChangeTextOnKeyBoardNavigation="True" DropDownAutoWidth="Enabled" EnableLoadOnDemand="True"
                    Filter="StartsWith" DataSourceID="ProjectSqlSource" DataValueField="project_id" DataTextField="Name" OnClientDropDownOpening="ProjectDropDownOpen">
                    <DefaultItem Text="Choose project" Value="-1" ViewStateMode="Enabled" />
                </telerik:RadComboBox>
            </td>
            <td>
                <telerik:RadComboBox ID="RadComboBoxPlan" runat="server" AutoPostBack="True"
                    OnSelectedIndexChanged="OnPlanTextChanged" ChangeTextOnKeyBoardNavigation="True"
                    DropDownAutoWidth="Enabled"
                    EnableLoadOnDemand="True" Filter="StartsWith" DataSourceID="PlanSqlSource" DataTextField="name" DataValueField="plan_id"
                    OnItemsRequested="RadComboBoxPlan_OnItemsRequested" ViewStateMode="Enabled">
                    <DefaultItem Text="Choose plan" Value="-1" />
     
                </telerik:RadComboBox>
            </td>
            <td>
                <telerik:RadButton runat="server" ID="newPlanDialog" ToolTip="Adds a new plan to the currently selected project" Text="Add new plan" AutoPostBack="False" />
            </td>
        </tr>
    </table>

  9. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 08 May 2015 Link to this post

    Casper,

    Attach sample project/page so we can debug your code.

    Thanks.

    Regards,
    Hristo Valyavicharski
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  10. Casper
    Casper avatar
    24 posts
    Member since:
    Mar 2015

    Posted 11 May 2015 in reply to Hristo Valyavicharski Link to this post

    There is a slight problem. The database I use contains company sensitive information(none of this in the code). Do you want me to upload only the code?
  11. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 12 May 2015 Link to this post

    Yes, please attach sample page.

    Thanks.

    Regards,
    Hristo Valyavicharski
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  12. Casper
    Casper avatar
    24 posts
    Member since:
    Mar 2015

    Posted 12 May 2015 in reply to Hristo Valyavicharski Link to this post

    I'm only allowed to post pictures (.gif, .jpg, .jpeg, .png)
  13. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 12 May 2015 Link to this post

    zip the file or use dropbox, onedrive, gooledrive.

    Regards,
    Hristo Valyavicharski
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  14. Casper
    Casper avatar
    24 posts
    Member since:
    Mar 2015

    Posted 12 May 2015 in reply to Hristo Valyavicharski Link to this post

    Won't upload the .zip here so you'll get a dropbox link
    https://www.dropbox.com/s/xmvp9uzv8i0cp7c/TRS.zip?dl=0
  15. Casper
    Casper avatar
    24 posts
    Member since:
    Mar 2015

    Posted 12 May 2015 in reply to Hristo Valyavicharski Link to this post

    I accidentally deleted the text after the link, sorry.

    The function is the first in the scripts.js and you should be able to see the problem if you just click "Add new plan"
  16. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 15 May 2015 Link to this post

    database is missing.

    Regards,
    Hristo Valyavicharski
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  17. Casper
    Casper avatar
    24 posts
    Member since:
    Mar 2015

    Posted 15 May 2015 in reply to Hristo Valyavicharski Link to this post

    I asked if you only wanted the code, because I am not allowed to post the database and you said yes. I have created a dummy database and changed the web.config to read from it. You should be able to download it from the same link as before.

     

    Thanks a lot :)

  18. Answer
    Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 20 May 2015 Link to this post

    It is not possible to use ClientID in external file.

    Try to add the following js:

                function getComboById(id) {
                    var combos = Telerik.Web.UI.RadComboBox.ComboBoxes;
                    for (var i = 0; i < combos.length; i++) {
                        var comboId = combos[i].get_id();
                        if (comboId.includes(id) > -1) {
                            return combos[i];
                        }
                    }
                    return null;
                }
     
     
    function newPlanShow(oWnd) {
        var prj = getComboById("RadComboBoxProject");
     ....
    }


    Regards,
    Hristo Valyavicharski
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  19. Casper
    Casper avatar
    24 posts
    Member since:
    Mar 2015

    Posted 20 May 2015 in reply to Hristo Valyavicharski Link to this post

    The code for the .aspx-file cannot run. the .includes method is not supported by comboId.

    I could however change the code to: 

    function getComboById(id) {
        var combos = Telerik.Web.UI.RadComboBox.ComboBoxes;
        for (var i = 0; i < combos.length; i++) {
            var comboId = combos[i].get_id();
            if (comboId === id) {
                return combos[i];
            }
        }
        return null;
    }

    To get the RCB object in the external file. i am now able to continue working.

    Thank you very much for your help, it is much appreciated.

    Kind regards

    Casper

     

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017