insert null value in foreign key field bound to openaccess

3 posts, 1 answers
  1. Amin
    Amin avatar
    4 posts
    Member since:
    May 2013

    Posted 14 May 2013 Link to this post

    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:
            <asp:Parameter ConvertEmptyStringToNull="true" DbType="Int32" Name="tblBankID" DefaultValue="0" />
     but not worked.
    help me plz.
  2. Answer
    Yordan avatar
    39 posts

    Posted 17 May 2013 Link to this post

    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.

    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.
  3. DevCraft banner
  4. Amin
    Amin avatar
    4 posts
    Member since:
    May 2013

    Posted 18 May 2013 Link to this post

    thank you very much Yordan ,
    it's really helpful and solved my problem,
    best regards, :)
Back to Top