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

Null values in DB causes exception when loaded to the AdvancedForm

3 Answers 62 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Jill-Connie Lorentsen
Top achievements
Rank 1
Jill-Connie Lorentsen asked on 04 May 2012, 11:34 AM

I am new to asp.net and ajax, so please excuse me if I don't express myself correctly

On my page I have a RadScheduler, and I use LinqDataSource to my database. In my database I have some columns which allow nulls.

I want to display these values in the AdvancedForm of my scheduler, and I have added them through the smart tag - ResourceTypes Collection Editor. The problem is that if some values are null I get an exception saying "Object reference not set to an instance of an object." It seems like it works fine for integer values, but not for string and boolean?

For the string columns I have modified the code in the DataClasses.designer.cs file, even though I don't like this solution...:

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Comment", DbType="VarChar(50)")]
    public string Comment
    {
        get
        {
            if( string.IsNullOrEmpty(this._Comment ))
                return string.Empty;
            else
                return this._Comment;
        }
        set
        {
            if ((this._Comment != value))
            {
                this.OnCommentChanging(value);
                this.SendPropertyChanging();
                this._Comment = value;
                this.SendPropertyChanged("Comment");
                this.OnCommentChanged();
            }
        }
    }

For boolean values I could do something like this:

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Private", DbType="Bit")]
    public System.Nullable<bool> Private
    {
        get
        {   
            if (this._Private.HasValue)
                return this._Private;
            else            
                return false;            
        }
        set
        {
            if ((this._Private != value))
            {
                this.OnPrivateChanging(value);
                this.SendPropertyChanging();
                this._Private = value;
                this.SendPropertyChanged("Private");
                this.OnPrivateChanged();
            }
        }
    }
But is a NULL value the same as false...? I would say no.

Could someone please tell me what I am missing here? 

Regards, Jill-Connie Lorentsen

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 09 May 2012, 09:00 AM
Hi Jill,

Usually, defining resources requires that you have separate data source for the resource type which is different from that of the appointment's data source. Is this your case? If not and you have just one data table, then you can consider using custom attributes.

Kind regards,
Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Jill-Connie Lorentsen
Top achievements
Rank 1
answered on 09 May 2012, 12:52 PM

Ok, so now I have two resources that is linked to another data source than that of the appointments, and with these two things seem to work as expected.

The Private and Comment field, which I'd defined as resources, are now custom attributes, along with another one called Municipality. But there must be something I'm missing, as it is not working as I would like. Private (bool) and Comment (string) allow nulls, whereas Municipality (string) does not.

1: If Private is NULL in the database it no value appears in the corresponding textbox in the advanced editor. If I edit some of the other parameters and hit Save, nothing happens. If I change Private to True/False the appointment is saved correctly to the database. But I should be allowed to save the appointment with Private=NULL, shouldn't I? And another thing, - how can I make the Private field have a corresponding check box, and not a text box?

2: If I want to insert a new appointment, and leave the Municipality field empty, and empty string is written to the database, and everything seems ok. But it is not, as Municipality is required. I've tried adding a validator as shown in your "298959_CustomizeAdvFormInFormCreated" example, but it doesn't work. In fact, I can't get the example to work either.

protected void RadScheduler_FormCreated(object sender, Telerik.Web.UI.SchedulerFormCreatedEventArgs e)
{        
        if ((e.Container.Mode == SchedulerFormMode.AdvancedEdit) || 
             (e.Container.Mode == SchedulerFormMode.AdvancedInsert))
        {
              
  
            #region ADD A NEW CUSTOM VALIDATOR FOR THE MUNICIPALITY FIELD
  
            CustomValidator validatorForMunicipality = new CustomValidator();
            RadScheduler scheduler = (RadScheduler)sender;
            validatorForMunicipality.ValidationGroup = scheduler.ValidationGroup;
            validatorForMunicipality.ControlToValidate = "Municipality";
            validatorForMunicipality.ErrorMessage = "Please enter municipality";
            validatorForMunicipality.ClientValidationFunction = "validationFunction";
            e.Container.Controls.Add(validatorForMunicipality);
  
  
            #endregion
    }
}

and in javascript

     <script type="text/javascript">
  
         //ADD A NEW CUSTOM VALIDATOR FOR THE MUNICIPALITY FIELD
         function validationFunction(source, arguments) {
             if (arguments.Value.length > 1) {
                 arguments.IsValid = true;
             } else {
                 arguments.IsValid = false;
             }
         }       
           
    </script>

Any ideas will be appreciated!

Regards, Jill-Connie Lorentsen

0
Peter
Telerik team
answered on 10 May 2012, 01:54 PM
Hello Jill-Connie Lorentsen,

It looks like you have a number of requirements about the advanced form and the best way to proceed is to consider using the Advanced Templates. Here is a demo for reference.

Regards,
Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Scheduler
Asked by
Jill-Connie Lorentsen
Top achievements
Rank 1
Answers by
Peter
Telerik team
Jill-Connie Lorentsen
Top achievements
Rank 1
Share this question
or