protected void btnSetParameter_Click(object sender, EventArgs e) { var selected = GetSelected(hdnParamSelected.Value); if (selected != null) { string paramName = hdnParam.Value.ToLowerCSafe(); var param = selected.Parameters[paramName]; if (param != null) { if (formElem.ValidateData()) { // Load value from the form control var ctrl = formElem.FieldControls[paramName]; if (ctrl != null) { var dataType = ctrl.FieldInfo.DataType; bool nullForDefaultValue = !DataTypeManager.IsNumber(TypeEnum.Field, dataType); // If value is not a number and it is default value of its data type (e.g. Guid.Empty for Guid), convert it to null object convertedValue = DataTypeManager.ConvertToSystemType(TypeEnum.Field, dataType, ctrl.Value, null, nullForDefaultValue); // Convert values to EN culture string value = ValidationHelper.GetString(convertedValue, String.Empty, CultureHelper.EnglishCulture); string displayName = ctrl.ValueDisplayName; if (String.IsNullOrEmpty(displayName) && !String.IsNullOrEmpty(value)) { displayName = value; param.ApplyValueTypeConversion = true; } param.Value = value; param.Text = displayName; param.ValueType = dataType; } pnlModalProperty.Visible = false; pnlFooter.Visible = false; } else { pnlModalProperty.Visible = true; pnlFooter.Visible = true; mdlDialog.Visible = true; mdlDialog.Show(); } } } }
private static bool UseNullInsteadOfDefaultValue(string dataType) { // For data types except numeric and boolean ones we need to use null value instead of default one // To avoid usage of Guid.Empty for Guid data type etc. return(!DataTypeManager.IsNumber(TypeEnum.Field, dataType) && !DataTypeManager.IsType <bool>(TypeEnum.Field, dataType)); }