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

Bind a Load On Demand RadComboBox inside an EditItemTemplate of RadGrid

1 Answer 213 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
bosseman
Top achievements
Rank 1
bosseman asked on 16 Feb 2012, 10:20 PM

I have a simple RadGrid that uses an edit form template. On edit, a number of radcombobox's are rendered. I have a radcombobox (call it cboUnit) that is disabled until a user selects a value in another radcombobox (call it cboMission) that is also within the edit form template. All of these comboboxs are load on demand.


What is the proper way to bind the 2nd radcombobox (cboUnit) that depends on a value from the 1st one (cboMission)?

I have tried a number of approaches with no success:


1. Declarative (in the aspx/ascx)? I set the datasourceid of the combobox cboUnit to the below entity data source.

 

  A. I first put the following datasource control in the ascx file (outside of the <FormTemplate>) tag

<asp:EntityDataSource ID="sdsUnit" runat="server"

    ContextTypeName="MiliTek.FleetBosse.FleetBosseEntities"

    EnableFlattening="False" EntitySetName="vUnitMissions"

    EntityTypeFilter="vUnitMission"

    Select="it.CustID, it.CustomerName, it.UnitID,it.UnitName" Where="it.MissionID=@MissionID">

    <WhereParameters>

        <asp:ControlParameter ControlID="cboMission" Name="MissionID" PropertyName="SelectedValue" DbType="Int32" />

    </WhereParameters>

</asp:EntityDataSource>

The page complains that it "Could not find control 'cboMission' in ControlParameter 'MissionID"

 

  B. So I put the entity data source control inside the <formTemplate> tag. I now get a different error: The DataSourceID of 'cboUnit' must be the ID of a control of type IDataSource. A control with ID 'sdsUnit' could not be found.

  C. I see that there is a onClientItemsRequested event but I don't want to use a webservice to bind to the combobox.


2. In the code behind?

 A. You can't simply hook up the "ItemsRequested" handler as the code-behind does not have visibility of the combobox as they are wrapped within a <FormTemplate> tag.

 B. I tried adding an event handler on the grid's ItemDataBound and ItemCreated event. I tried something like the below in one, then both of these events:

  Dim cboUnit As RadComboBox = DirectCast(item.FindControl("cboUnit"), RadComboBox)

  If cboUnit IsNot Nothing Then AddHandler cboUnit.ItemsRequested, AddressOf cboUnit_ItemsRequested

I've stepped through the code and see that the lines are executed, but every time I click the combobox, I get the dreaded "There is no assigned data source. Unable to complete callback request". The cboUnit_ItemsRequested method does not even get fired.

I then added the addhandler method within the 1st comboboxs selectedindexchanged event, but still get the same error.

I have turned of RadAjaxManager to see if that would resolve the problem but it still persists.

I'm ready to turn off load on demand if I can't figure this out - it is very frustrating. Can you tell me what I'm doing wrong?

Thank you,

Jim

1 Answer, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 21 Feb 2012, 01:44 PM
Hi James,

Have you seen the online Code Library on how to implement related RadComboBoxes inside a RadGrid? You could download the sample project attached to the CL article and decide if it would be useful for you.

Regards,
Ivana
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
ComboBox
Asked by
bosseman
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Share this question
or