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

[Solved] SelectedValue binded with Null

6 Answers 240 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mohamed
Top achievements
Rank 1
Mohamed asked on 12 May 2008, 04:31 PM
Hi all
In the detailView control'd template, I am using a RadComboBox with its SelectedValue binded.
When the binded column in the dataSource returns NULL it throws an exception. Is there a way to setup the RadCombo so to display nothing (empty string) when the binded value is NULL (Database null or .NET nullable type)?

6 Answers, 1 is accepted

Sort by
0
Collin
Top achievements
Rank 1
answered on 13 May 2008, 07:58 PM
You could use coalesce to pull back '' instead of null in the SQL statement of your dataset.

Instead of select myvalue

do

select coalesce(myvalue,'') as myvalue.

0
Veselin Vasilev
Telerik team
answered on 15 May 2008, 08:32 AM
Hello Mohamed,

You can use ISNULL in your query as well:

SELECT ID, ISNULL(Name''as Name, Description FROM [Buildings] 


All the best,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Omar Shraim
Top achievements
Rank 1
answered on 17 May 2008, 06:30 PM
I have the same problem as Mohammad's. The suggested solution will not work in this case as my BL uses custom business objects generated by an ORM tool (LLBLGen). LLBLGen generates an entity for each table and if the table's column allows null, the resulting entity property would be a Nullable type.
example: Fund table has a Country column (GUID) that allows null. The generated FundEntity would have a Country property of type nullable GUID (GUID?).

The case becomes then when binding the ComboBox (or even a TexBox or DateTimePicker) to an entity property that is of a Nullable type, it throws a runtime exception if the source property has NULL but would work fine otherwise?
0
Veselin Vasilev
Telerik team
answered on 19 May 2008, 12:45 PM
Hi Omar,

Which version of the Combobox do you use?
I tried to reproduce the problem but to no avail.
I have attached my files - you can bind it to your datasource and test.
When the value in the DB is null - the combobox shows empty text.


Best wishes,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Omar Shraim
Top achievements
Rank 1
answered on 19 May 2008, 01:00 PM
Thank you for answering. The NULL problem I am having is not to do with DB NULL but rather with Nullable type NULL.
So if the datasource has a property FundId that is a nullable integer (int?) and the selectedValue of the comboBox is binded to this property, I get the exception when the property FundId.HasValue is false (meaning the nullableType is NULL) but works fine when the FundId.HasValue is true (meaning the nullableType is NOT NULL)?
0
Veselin Vasilev
Telerik team
answered on 22 May 2008, 12:27 PM
Hi Omar,

Can you isolate the problem in a small and running project and attach it to a new support ticket please?
This will help us resolve the problem quicker.

Thanks

Best wishes,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox
Asked by
Mohamed
Top achievements
Rank 1
Answers by
Collin
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Omar Shraim
Top achievements
Rank 1
Share this question
or