This is a migrated thread and some comments may be shown as answers.

RCB with datasource returning empty items

17 Answers 59 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Casper
Top achievements
Rank 1
Casper asked on 30 Apr 2015, 09:20 AM

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

17 Answers, 1 is accepted

Sort by
0
Casper
Top achievements
Rank 1
answered on 30 Apr 2015, 09:22 AM

[quote] 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[/quote]

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.

0
Hristo Valyavicharski
Telerik team
answered on 05 May 2015, 05:24 AM
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.

 
0
Casper
Top achievements
Rank 1
answered on 05 May 2015, 01:16 PM
I'm sorry should've mentioned that I started by using $find, but it returns null 
0
Hristo Valyavicharski
Telerik team
answered on 08 May 2015, 06:44 AM
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.

 
0
Casper
Top achievements
Rank 1
answered on 08 May 2015, 08:03 AM

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?

0
Casper
Top achievements
Rank 1
answered on 08 May 2015, 08:08 AM

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>

0
Hristo Valyavicharski
Telerik team
answered on 08 May 2015, 01:50 PM
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.

 
0
Casper
Top achievements
Rank 1
answered on 11 May 2015, 10:04 AM
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?
0
Hristo Valyavicharski
Telerik team
answered on 12 May 2015, 09:30 AM
Yes, please attach sample page.

Thanks.

Regards,
Hristo Valyavicharski
Telerik
 

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

 
0
Casper
Top achievements
Rank 1
answered on 12 May 2015, 10:10 AM
I'm only allowed to post pictures (.gif, .jpg, .jpeg, .png)
0
Hristo Valyavicharski
Telerik team
answered on 12 May 2015, 11:50 AM
zip the file or use dropbox, onedrive, gooledrive.

Regards,
Hristo Valyavicharski
Telerik
 

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

 
0
Casper
Top achievements
Rank 1
answered on 12 May 2015, 11:53 AM
Won't upload the .zip here so you'll get a dropbox link
https://www.dropbox.com/s/xmvp9uzv8i0cp7c/TRS.zip?dl=0
0
Casper
Top achievements
Rank 1
answered on 12 May 2015, 12:16 PM
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"
0
Hristo Valyavicharski
Telerik team
answered on 15 May 2015, 07:42 AM
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
0
Casper
Top achievements
Rank 1
answered on 15 May 2015, 10:31 AM

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 :)

0
Accepted
Hristo Valyavicharski
Telerik team
answered on 20 May 2015, 12:26 PM
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
0
Casper
Top achievements
Rank 1
answered on 20 May 2015, 12:43 PM

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

 

Tags
ComboBox
Asked by
Casper
Top achievements
Rank 1
Answers by
Casper
Top achievements
Rank 1
Hristo Valyavicharski
Telerik team
Share this question
or