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

insert null value in foreign key field bound to openaccess

2 Answers 60 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Amin
Top achievements
Rank 1
Amin asked on 14 May 2013, 11:06 AM
hi guys.
i have a problem in binding open acess datasource to radcomboBox,
i have a combobox with an empty item (like this : combo.Items.Insert(0, new RadComboBoxItem("",String.Empty)); )
and it's bound to a foreign key filed in radGrid. but when trying to insert or update with empty value of comboBox, javaScript error occurred(Input string was not in correct format).
but when inserting with selected a value from comboBox it's worked properly.
even added insert parameter like this:
<InsertParameters>
        <asp:Parameter ConvertEmptyStringToNull="true" DbType="Int32" Name="tblBankID" DefaultValue="0" />
</InsertParameters>
 but not worked.
help me plz.

2 Answers, 1 is accepted

Sort by
0
Accepted
Yordan
Telerik team
answered on 17 May 2013, 10:14 AM
Hi Amin,

Probably the exception that you see is due to the fact that at some point in time the application tries to convert empty string to int value which is not possible. Please use in the grid GridDropDownColumn not a RadComboBox, to show the categories. Here is a complete example how this can be done. If an empty item have to be shown in the dropdown please use the property EnableEmptyListItem="true" and optionally EmptyListItemText and EmptyListItemValue. The code is similar to the following:

<telerik:GridDropDownColumn UniqueName="DropDownCategoryListColumn" ListTextField="CategoryName"
                          ListValueField="CategoryID" DataSourceID="OpenAccessLinqDataSource2" HeaderText="Category"
                          DataField="CategoryID" DropDownControlType="RadComboBox" AllowSorting="true"
                          ItemStyle-Width="120px" EnableEmptyListItem="true" EmptyListItemText=" This is the text of an empty item " EmptyListItemValue="1" />

This GridDropDownColumn have to be bound to OpenAccessLinqDataSource that shows categories:
<telerik:OpenAccessLinqDataSource ID="OpenAccessLinqDataSource2" runat="server" ContextTypeName="WebApplication1.EntitiesModel" EnableDelete="True" EnableInsert="True" EnableUpdate="True" EntityTypeName="" ResourceSetName="Categories" />

If the suggested approach is not suitable in your scenario or if you have any more questions do not hesitate to ask us.


Regards,
Yordan
the Telerik team
OpenAccess Samples Kit boasts 50+ sample applications providing diverse real-life business solutions. Click to read more and see OpenAccess ORM in action.
0
Amin
Top achievements
Rank 1
answered on 18 May 2013, 07:41 AM
thank you very much Yordan ,
it's really helpful and solved my problem,
best regards, :)
Tags
General Discussions
Asked by
Amin
Top achievements
Rank 1
Answers by
Yordan
Telerik team
Amin
Top achievements
Rank 1
Share this question
or