protected void ClearForm()
 {
     ((TextBox)AddPatientFormView.FindControl("NameTextBox")).Text = "";
     ((DropDownList)AddPatientFormView.FindControl("GenderDropdownList")).SelectedIndex = 0;
     ((TextBox)AddPatientFormView.FindControl("AddressTextbox")).Text = "";
     ((TemplateControls_DatePicker)AddPatientFormView.FindControl("DateOfBirthDatePicker")).SelectedDate = DateTime.Now.Ticks;
 }
    protected void InsertButton_Click(object sender, EventArgs e)
    {
        var patientName        = ((TextBox)AddPatientFormView.FindControl("NameTextBox")).Text;
        var patientGender      = ((DropDownList)AddPatientFormView.FindControl("GenderDropdownList")).SelectedValue;
        var patientAddress     = ((TextBox)AddPatientFormView.FindControl("AddressTextbox")).Text;
        var patientDateOfBirth =
            ((TemplateControls_DatePicker)AddPatientFormView.FindControl("DateOfBirthDatePicker")).SelectedDate;

        System.Collections.Specialized.ListDictionary dic = new System.Collections.Specialized.ListDictionary();
        dic.Add("Name", patientName);
        dic.Add("Gender", patientGender);
        dic.Add("Address", patientAddress);
        dic.Add("DateOfBirth", patientDateOfBirth);


        if (AddPatientDataSource.Insert(dic) == 0)
        {
            //fail
            ResultAlert.SetResultAlert("An error occured!",
                                       TemplateControls_ResultAlert.AlertTypeError);
        }
        else
        {
            // success
            ResultAlert.SetResultAlert("Patient inserted successfully!",
                                       TemplateControls_ResultAlert.AlertTypeSuccess);
            ClearForm();
        }
    }
    protected void AddPatientDataSource_Inserting(object sender, LinqDataSourceInsertEventArgs e)
    {
        // get the date picker control from the form view
        var datePicker = (TemplateControls_DatePicker)AddPatientFormView.FindControl("DateOfBirthDatePicker");

        // set the date of birth of the new patient
        ((Patient)e.NewObject).DateOfBirth = datePicker.SelectedDate;
    }