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

RadComboBox in GridTemplateColumn with EntityDataSource

4 Answers 176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nor
Top achievements
Rank 1
Nor asked on 09 Jun 2011, 10:54 AM
Hi.

I have a RadComboBox in a GridTemplateColumn's EditTemplate like this:

....
<
telerik:GridTemplateColumn UniqueName="Unit.Name" HeaderText="Unit" DataField="Unit.Id"
    SortExpression="Unit.Id" ItemStyle-Width="250px">
    <ItemTemplate>
        <%# DataBinder.Eval(Container.DataItem, "Unit.Name")%>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadComboBox runat="server" ID="UnitComboBox" EnableLoadOnDemand="True" SelectedValue='<%#Bind("Unit.Id")%>'
            DataTextField="Name" DataSourceID="UnitEntityDataSource"
            DataValueField="Id" AutoPostBack="true" HighlightTemplatedItems="true" Height="250px" Width="250px" DropDownWidth="600px">
....

The Grid uses one EntityDataSource and the combobox another.

This works perfectly when updating existing rows, but when I insert a new row it crashes with:

DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'Unit'.

I guess this is because Unit is null when I insert a new object and therefore cant resolve Unit.Id. 

All the existing solutions recommend that you cancel the insert command and insert a dummy row, this would work if it was a ordinary column, but since its an entity I have to specify the relation, hence Unit.Id and not UnitId (which is the columnname in the grids entitydatasource)

I suspect this is the same problem that FreshOne reported here: Forum link

Ive also tried to behind selectedvalue code behind (trying to distinguish between update and insert) but then no values get updated instead.

Can I clarify my problem further?
Best Regards 
N.

4 Answers, 1 is accepted

Sort by
0
Accepted
Mira
Telerik team
answered on 13 Jun 2011, 01:38 PM
Hello Nor,

When you use Load On Demand or Automatic Load On Demand of the RadComboBox,  you should add the previously selected item on ItemDataBound of the grid only when in 'Edit' Mode.
You can see how it is done in the Combo in Grid demo.

I hope this helps.

Greetings,
Mira
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Nor
Top achievements
Rank 1
answered on 14 Jun 2011, 07:54 AM
Ok, I understand, but it doesn't fix my problem. 
Edit works well, its insert that doesn't work. Mainly because I cant do a 

'<%#Bind("Unit.Id")%>'

(I'm guessing here)
Since Unit is Null (remember i'm using EF datasource).

Can I somehow only set selectedvalue on a update?



0
Nor
Top achievements
Rank 1
answered on 14 Jun 2011, 05:26 PM
Ok, I fixed it. I link Mira posted sent me in the right direction.
Anyway, the solution went from simple to quite complicated.

I had to save the selected value in the Session, like the link suggested, however is this really a good idea? What should I have done if I had multiple rows to edit at the same time?

Anyway, I still feel like there should be an easier solution.

Thanks.
0
Mira
Telerik team
answered on 16 Jun 2011, 01:55 PM
Hello Nor,

If you do not want to store the value of the selected item in session, you can set only the SelectedText property of the RadComboBox.
Another option is to use the GridDropDownColumn which as of version 2010.Q2 of Telerik RadControls supports automatic load-on-demand for the RadComboBox editor.
Please examine the Customize/configure GridDropDownColumn help topic for additional information.

I hope this helps.

Kind regards,
Mira
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Nor
Top achievements
Rank 1
Answers by
Mira
Telerik team
Nor
Top achievements
Rank 1
Share this question
or