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

two depended combobox in template form

9 Answers 236 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 21 Feb 2011, 07:45 PM
I am trying to reproduce the functionality as posted in the article below for an older version of the controls. I am using VB for this project and not C#, but was able to convert the code since I know both languages. However I suspect that the problem is with the actual responsescript. I have spent two days working on this solution, your assistance is appreciated. I am using RadControls for ASPNET AJAX Q3 2008

http://www.telerik.com/community/forums/aspnet/grid/two-depended-combobox-in-template-form.aspx

I am unable to use responsescripts for the grid, and have used the AjaxPanel to add the responsescripts as suggested in some articles I have read. The responsescripts get added to the panel (I have stepped through the code and know the lines are executing), but the javascript call to the firstcombo, secondcombo throws and error, firstcombo is undefined, when the page loads. I made modifications to the responsescript replacing window with $find as below:

 

Dim responseScript As String = String.Format("var secondCombo = $find['{0}'];var firstCombo = $find['{1}'];SecondComboInitialize();", e.Item.FindControl("cboActiveNormDoc").ClientID, e.Item.FindControl("cboNormDocStatus").ClientID)

 

9 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 25 Feb 2011, 10:02 AM
Hi Thomas,

The forum thread that you referred to suggests workaround for achieving load on demand functionality for an older version of the classic controls for ASP.NET without the use of Ajax.
To achieve similar functionality in the Ajax version of the controls you can check this live demo.
Additionally for the scenario with two or more related ComboBoxes you can use the approach shown in this demo. Basically you need to handle the two events: OnClientSelectedIndexChanging and OnItemsRequested

All the best,
Marin
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Thomas
Top achievements
Rank 1
answered on 26 Feb 2011, 09:14 PM
Hello,
As I can assure you, if I had access to the comboboxes in the code-behind this would be no problem. I have a form similar to the second demo, and it works just fine. I am loading a combobox with a list of muscle groups, and on selection, need to populate the second combo box with asssociated exercises. As the comboboxes are within the radgrid form template that pops up, there are no events associated with them, and in fact I can not call them at all from the code behind. I followed the original post and was able to get everything to work, except for the responsescripts, which is the javascript call to make the whole thing work. The task is simple, I have two comboboxes within the radgrid edit popup template, and I need the second to populate based on values from the first. Neither demo you posted had the combo's inside a grid, they were straight on the page, and that is why I requested assistance.
Regards,
Thomas
0
Marin
Telerik team
answered on 01 Mar 2011, 05:49 PM
Hi Thomas,

You can obtain access to the comboboxes both client and server-side.
I have prepared a sample project based on the previously mentioned demos with two comboboxes in grid popup edit form template.
On the server you can populate the first combo box in the ItemDataBound event like this:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {
            RadComboBox radComboBox = (e.Item as GridEditFormItem).FindControl("RadComboBox1") as RadComboBox;
            LoadCategories(radComboBox);
        }
    }

On the client I use the $telerik.findComboBox(clientID) method to retrieve the second combo and populate it accordingly.

function LoadItems(combo, eventArgs)
            {
                //the next div sibling of the current combo box element should be the second combo
                var combo2ID = $(combo.get_element()).siblings("div")[0].id;
                var itemsCombo = $telerik.findComboBox(combo2ID);
               //....
           }


Kind regards,
Marin
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Thomas
Top achievements
Rank 1
answered on 04 Mar 2011, 06:45 PM
Hi,
Thanks for you assistance. I was able to get the project you posted to run, and proceeded to port the code to my project.
The main problem that I have been having, after multiple attempts, is that the code is failing on the first line of the javascript code block. After some considerable trial and error, I found out that the javascipt block is not working because of this reference:

 

<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />

I was not sure these references were needed because of the comment:

 <%

--Needed for JavaScript IntelliSense in VS2010-- %> -I am using VS2008
 

 

 

So initially I didn't add them and JavaScript errors were occuring. 

 

 

 

When this line is added, the project fails to load the ASP.net Ajax framework. I have created a page in my project and copied your code in, so I have made no adjustments.
Your help is appreciated.
Regards,
Thomas

 

0
Marin
Telerik team
answered on 07 Mar 2011, 10:10 AM
Hello Thomas,

The specified reference is included in newer version of RadControls, for older versions you do not need it. Also when using VS 2008 you should use the standard ASP.NET ScriptManager, instead of RadScriptManager. I have made the appropriate modifications to the code and tested it in default VS 2008 WebSite project with Q3 2008 version of RadControls - it works ok.

Please have a look at the attached sample.

All the best,
Marin
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Thomas
Top achievements
Rank 1
answered on 11 Mar 2011, 02:34 PM
Okay. so I was able to get everything working, and that is awesome, thank you so much. This works perfectly for the add new record feature, but I need to be able to select the value when the user selects edit. I currently set the value of the other contols with this syntax :

Text

 

='<%# Eval ( "Weight" ) %>'

 


However, this method is not possible due to the way the combo's load. Any idea how I can set these values, I am assuming I will need to do this in Javascript, or code behind, but maybe I am just missing somethign and was hoping you have a simple solution.
Thanks,
Thomas
0
Marin
Telerik team
answered on 15 Mar 2011, 03:20 PM
Hello Thomas,

I am glad to hear the proposed solution worked for you.

As for the selecting of the proper item of the combo box during edit mode you need to do this in code behind in the ItemDataBound event. For more detailed information and code sample you can refer to the following code library. Basically when the combo is loaded in edit mode it does not have items initially (that's why the Eval method in the markup does not work). So you have to add an item with the proper text and value (taken from the grid item in the ItemDataBound event). 
Also note that in this case the LoadOnDemand functionality is triggered when you delete text of the preselected item in the combo, then all the other items are loaded as well.
Live example of this can also be seen in the following demo.

Greetings,
Marin
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Theofanis Markou
Top achievements
Rank 1
answered on 20 Dec 2011, 02:29 PM

Hi,
Have you got the code for RadGridRelatedComboBoxes.zip in VB.NET ???

Thanks in advance.
0
Shinu
Top achievements
Rank 2
answered on 21 Dec 2011, 06:45 AM
Hello,

Here is the link for code-converter.
http://converter.telerik.com/.

-Shinu.
Tags
Grid
Asked by
Thomas
Top achievements
Rank 1
Answers by
Marin
Telerik team
Thomas
Top achievements
Rank 1
Theofanis Markou
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or