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

Null Foreign Key via ComboBox

1 Answer 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
PH
Top achievements
Rank 2
PH asked on 03 Aug 2009, 02:15 PM
I have a table with a foreign key which is set via a RadComboBox control on an Edit Form Template.  All works well if a value is picked from the combo box, but it is possible for this field to be null.  To allow this, I have set up an item in the combo which has "unknown" as its text and a blank value property.  The lookup values via a datasource are appended to this in the standard manner.

However, despite Linq defining this field as being nullable, unless I pick a value from the combo box the RadGrid won't save it.  Unbinding the combo box (thus effectively ignoring the field) is fine - the new row is added without fuss, so the field can be null, it's just that a blank value field in the RadComboBox obviously doesn't equate to this at save time.

So my question is, what's the best way to handle lookups for foreign key fields where the foreign key can be null?  (I should add that the foreign key field is an Int32, in case that matters).

Thanks,
Peter

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 06 Aug 2009, 12:15 PM
Hi chairmaker,

You can find attached a small web site I have created that demonstrates the functionality you are describing. Two things to note: I add the additional unknown item in RadComboBox in its DataBound event. Additionally, in my EditForm template, I use the combo's SelectedValue property with the Bind() expression to introduce two-way binding of the combo and the data source. My AccessDataSource object handles updates automatically.

Greetings,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
PH
Top achievements
Rank 2
Answers by
Veli
Telerik team
Share this question
or