Last post Jun 08, 2011 08:43 AM by khoshrou
Jun 06, 2011 11:56 AM|khoshrou|LINK
I have entity object that has a nullable GUID property. I use a ObjectDataSource to bind a GridView to a list of my entity object. I use a DropDown (ComboBox) to select a value for this GUID property. ListItem accepts string for value and text for dropdown
items. I use empty string for null value but ObjcetDataSource cant convert empty string to NULL or DBNull.Value in this case I get an Exception that says "Cant Convert System.String to System.GUID.
Does any body know how to resolve this problem?
Jun 06, 2011 12:00 PM|anas|LINK
Try to use "Object" for the paramter type instead of Guid.
Jun 06, 2011 12:07 PM|khoshrou|LINK
I cant change the entity object.
Jun 07, 2011 07:34 AM|anas|LINK
Try to Set the "ConvertEmptyStringToNull" property for your paramter to true:
<asp:ControlParameter ConvertEmptyStringToNull="true" Name="..." />
If it doesn't worked, try this solution:
Instead of using ControlParameter, use the normal Parameter like below:
<asp:Parameter Name="..." Type="Object" />
Then, you should handle the Selecting event of the ObjectDataSource and pass the selected value programatically like below:
protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
//There is no selected value , so we pass null for your method paramter
e.InputParameters = null;
//There is a value selected in the DropDowList, so we pass it to the
e.InputParameters = DropDownList1.SelectedValue;
Jun 08, 2011 01:44 AM|decker dong - msft|LINK
Please pay attention to it that Guid is a very special string which has a serious of chars combined together. So a single string cannot be substituted for that.
And what's more, Please try the Moderator's idea and make sure that your Dropdownlist's SelectedValue should be a right proper form of GUID, please use "new Guid().ToString()" to generate it.
Jun 08, 2011 08:43 AM|khoshrou|LINK
Hi Guys none of the above solutions worked for me. I did override ObjectDataSource and ObjectDataSourceView
In update and Insert method I checked Nullable Guid's and replaced empty string with null.
It works fine.
Thanks a lot