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

Wrong key value bound to SelectedValue via Eval()

2 Answers 159 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 2
Alexander asked on 27 Oct 2008, 11:49 AM

There is a RadGrid, which is used to show and edit XML-data in a grid form. And the same XML-data can be edited manually.

There is a ComboBox on the RadGrid’s edit template. It is used to select a value from dictionary (a database table of key –value pairs ).

ComboBox is bound to a field in the grid’s datasource:

<telerik:RadComboBox ID="ddProductName" runat="server" DataSourceID="dsProducts" DataTextField="Name" DataValueField="ProductID" SelectedValue='<%# Eval("ProductID") %>' />

The problem is, that since grid’s underlying XML is manually editable, Eval() function may return invalid key values. That is, a value that is not present in the dictionary table.  In such cases, the above binding to SelectedValue attribute fails, and the whole page crashes.

What do I do to overcome this problem?

2 Answers, 1 is accepted

Sort by
0
Accepted
Simon
Telerik team
answered on 27 Oct 2008, 04:51 PM
Hi Alexander,

Why don't you try setting the selected value of the ComboBox in the OnItemDataBound event handler of the Grid?

In the event handler you can find the ComboBox and verify whether the ProductID value exists in its Items collection and defaulting to the first Item in case it does not.

Regards,
Simon
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Alexander
Top achievements
Rank 2
answered on 29 Oct 2008, 10:58 AM
Thank you! Sure enough, it works with grid's OnItemDataBound.
Tags
ComboBox
Asked by
Alexander
Top achievements
Rank 2
Answers by
Simon
Telerik team
Alexander
Top achievements
Rank 2
Share this question
or