Dynamic Data Loading


ZSURVEY provide the ability to bind the survey data direct to the web controls without using XML files. The Survey Builder Web Control can bind the XML definition of the survey on the fly and load the pages, questions, branching rules and media files of the survey without using any physical files.

The sample below show how to bind the survey XML to the Survey Builder Web Control.

private string xml = @"<survey version='1.2'>
                              <meta>
                                <id>sample</id>
                                <title>Sample Survey</title>
                                <description>This is a sample survey description</description>
                                <endtitle>Thank You</endtitle>
                                <enddescription>Thank you for taking this survey</enddescription>
                                <startdate>01/01/0001</startdate>
                                <enddate>12/31/9999</enddate>
                                <quote>2000</quote>
                                <progressbar>true</progressbar>
                              </meta>
                              <pages>
                                <page id='1' title='Start Page' 
                                             description='This is a sample start page' />
                              </pages>
                              <questions>
                                <question id='1' type='singlechoice' page='1'>
                                  <body>What is your gender?</body>
                                  <remarks>
                                  </remarks>
                                  <footer>
                                  </footer>
                                  <mandatory>false</mandatory>
                                  <otherenabled>false</otherenabled>
                                  <randomized>false</randomized>
                                  <dropdownlist>false</dropdownlist>
                                  <horizontal>false</horizontal>
                                  <choices>
                                    <choice>Male</choice>
                                    <choice>Female</choice>
                                  </choices>
                                  <media />
                                  <rules />
                                </question>
                              </questions>
                            </survey>";



    protected override void OnInit(EventArgs e)
    {
        // Register OnSaveSurvey event
        this.ucSurveyBuilderWebControl.OnSaveSurvey += new 
MentorLogic.Engines.Zodiac.Web.OnSaveSurvey(ucSurveyBuilderWebControl_OnSaveSurvey);

        base.OnInit(e);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Set the XML definition of the survey. This XML can be retrieved from the database.
            this.ucSurveyBuilderWebControl.Xml = xml;           
        }
    }

    protected void ucSurveyBuilderWebControl_OnSaveSurvey(object sender, SurveyArgs args)
    {
        // Receive the new XML definition of the survey after save
        string surveyXml = args.Xml;

        // TODO: surveyXml string to be saved on the database
    }

See Also