phdcc.Data DNN modules
  search
Powered by FindinSite-MS
phdcc.Data.View: Overview
phdcc.Data: Overview Examples Getting Started Security Database Versions
phdcc.Data.Form: Form Profile/Register forms Form editing Languages Layout Questions Form hooks Admin
phdcc.Data.View: View  phdcc.Data.List: List phdcc.Data.Search: Search
Last updated: CC 24/4/09

phdcc.Data.View Overview

phdcc.Data.View is a DNN 4 module to display a single result produced by a form created using the phdcc.Data.Form module.

phdcc.Data.View contains a wizard that creates a simple template that displays the result. The template is a standard ASP.NET user control in a file - you can edit this to customise the output so that it appears as you wish.

Important security notes

Note carefully that module users with Edit permissions (ie Administrators etc) can enter ASP.NET code that is then run - therefore be very careful to whom you give Edit permissions.

Form values for SuperUser users such as host are not returned.

If you output any information that a user provided, please remember to make it HTML safe by calling Server.HtmlEncode().

Usage scenario

  1. Many users fill in a form giving their details, using phdcc.Data.Form
  2. Typically, an administrator will moderate new submissions in phdcc.Data.Form
  3. Others want to look through this information so they enter a search request, using phdcc.Data.Search
  4. Multiple hits are displayed to the user, using phdcc.Data.List
  5. Clicking on a single result shows full details, using phdcc.Data.View

So phdcc.Data.View is primarily aimed at showing the answers to the questions posed in one form. For a 'Profile' form, phdcc.Data.View can also show results from other forms that the user has filled in. In addition, any other (per-user) data can be shown, eg from information stored by DNN or other third-party modules.

Using phdcc.Data.View

To use phdcc.Data.View:

  1. After setting up this View, you will usually want to add an instance of the phdcc.Data.List module to another page.
  2. In the DNN Control Panel, add a new instance of the phdcc.Data.View module to a page, entering your desired container name.
  3. Now, in the module Settings, specify which form's results you want to view - see below.
    First specify a form in the Settings for phdcc.Data.View
  4. Then, use the Edit Template option to create a template for the result - again, see below.
    Then create a template for the result using the Edit Template option of phdcc.Data.View

There are also these further options - selected in Settings:

phdcc.Data.View module settings

phdcc.Data.View Settings

Click on the Settings button (or select Settings from the module menu). Expand the phdcc.Data.View section and choose/enter these values:

Click on Update to save your changes.

(Please do not put two forms with the same Form Id on the same DNN page - phdcc.Data.View does not know how to distinguish between and so will send you to the Settings page.)

Edit Template

A template is needed to define what is displayed for the chosen result. An initial template can be set up for you by a phdcc.Data.View wizard. You can then tailor it to fit your precise requirements within Edit Template. Alternatively you can upload your own template using FTP or [Admin][File Manager] into the DesktopModules\phdcc.Data.View directory, and then select it in Edit Template.

A template is a standard ASP.NET user control file that can contain both HTML and code, either VB or C# - see examples below.
Use a separate file for each of your templates, ie for each different instance of the phdcc.Data.View module on your site.

When you first enter Edit Template, click on "Create a new template using a wizard":
Choose 'Create a new template using a wizard' to make an initial template
(Alternatively, you can click on "Choose a different template" to pick an existing template or one that you have uploaded to the DesktopModules\phdcc.Data.View directory. Templates must start with precisely the correct text, as described below.)

Enter a filename for your template, then click on "Create template file using a wizard". After this, you will need to confirm that you want the file created.
Enter a filename for your template, then click on 'Create template file using a wizard'

A template is created that contains all the questions on your form. The template is laid out in a table, with group name on the left, questions and answers in the middle. Note that by default, results for email type questions are replaced with EMAIL SUPPRESSED; you can change the code to show the email if you wish.

The generated template is now shown in an edit box. Edit this as required and then press Update.
Edit the generated template as required and then press Update

This a result displayed by phdcc.Data.View using the above template:
Sample output for a simple test form

phdcc.Data.View templates

The "Create a new template" wizard creates a template user control file with the correct code at the start. When editing within Edit Template, you do not see this initial code. However, if you create your own template user control file from scratch, you must make sure that the correct code appears at the start. For Visual Basic, this is:

<%@ Control Language='VB' ClassName='ControlName' Inherits='phdcc.Data.View.TemplateBaseVB' CodeFile='TemplateBase.ascx.vb' AutoEventWireup='true' %>
<%@ Import Namespace='phdcc.Data.View' %>
<% SetResultSet() %>

where ControlName corresponds to the template filename with ".ascx" removed. For C#, the correct initial code is:

<%@ Control Language='C#' ClassName='ControlName' Inherits='phdcc.Data.View.TemplateBaseCS' CodeFile='TemplateBase.ascx.cs' AutoEventWireup='true' %>
<%@ Import Namespace='phdcc.Data.View' %>
<% SetResultSet(); %>

The template shows a single result. Your template code can be in either Visual Basic (VB) or C-Sharp (C#). The template can contain any HTML and use all normal ASP.NET code. However it will typically use various phdcc.Data.View helper functions to access form results. The "Create a new template" wizard uses the Form and FormValues helper functions.

VB template simple example

The following VB code is in a file called ShowProjectVB.ascx so that it matches the chosen ClassName property (without the extension). The filename must not start with a number and should not contain periods and spaces. The code starts with the required standard lines.

<%@ Control Language='VB' ClassName='ShowProjectVB' Inherits='phdcc.Data.View.TemplateBaseVB' CodeFile='TemplateBase.ascx.vb' AutoEventWireup='true' %>
<%@ Import Namespace='phdcc.Data.View' %>
<% SetResultSet() %>


<h1>Project details:</h1>
<p>
<b><%=Form("idPP_Name")%></b><br />
<%=Form("idPP_Description")%>
</p>

This code calls the phdcc.Form.View SetResultSet function to get the results that we want to look at.

This code then contains some HTML with a couple of calls to the phdcc.Form.View Form function to return the answers to two questions: those with a QuestionId of "idPP_Name" and "idPP_Description".

C# template simple example

The C# equivalent code is very similar, in a file with matching filename ShowProjectCS.ascx

<%@ Control Language='C#' ClassName='ShowProjectCS' Inherits='phdcc.Data.View.TemplateBaseCS' CodeFile='TemplateBase.ascx.cs' AutoEventWireup='true' %>
<%@ Import Namespace='phdcc.Data.View' %>
<% SetResultSet(); %>


<h1>Project details:</h1>
<p>
<b><%=Form("idPP_Name")%></b><br />
<%=Form("idPP_Description")%>
</p>

phdcc.Data.View functions, VB

The following phdcc.Data.View properties and functions can be called from your code. All the Form... functions that return strings are HTML safe. For FormValues and FormXValues, make sure that you call Server.HtmlEncode() on any user provided data.
Functions marked *** are only usable on results from 'Profile' forms.

ReadOnly Property rsi() As phdcc.Data.View.ResultSetInfo
Returns the current results set - will be null if no result being displayed

ReadOnly Property ResultSetId() As Integer
Returns the current results set identifier

ReadOnly Property UserId() As Integer
Returns the current UserId, -1 if not logged in

ReadOnly Property UserName() As String
Returns the current UserName, or empty if not logged in

ReadOnly Property ResultTime() As DateTime
Returns the DateTime when the form was submitted or approved

Function Form(ByVal QuestionIdName As String) As String
Returns the user's answer to this question

Function Form(ByVal QuestionIdName As String, ByVal QuestionOptionIdName As String) As String
Returns the user's answer to this question's option, ie use for checkboxes or radiobuttons question types

***Function FormX(ByVal FormIdName As String, ByVal QuestionIdName As String) As String
Returns the user's answer to this question on form 'FormIdName'

***Function FormX(ByVal FormIdName As String, ByVal QuestionIdName As String, ByVal QuestionOptionIdName As String) As String
Returns the user's answer to this question's option on form 'FormIdName'

Function FormDefault(ByVal QuestionIdName As String, ByVal QuestionOptionIdName As String, ByVal DefaultValue As String) As String
Returns the user's answer (to this question's option); returns 'DefaultValue' if no answer was given

***Function FormXDefault(ByVal FormIdName As String, ByVal QuestionIdName As String, ByVal QuestionOptionIdName As String, ByVal DefaultValue As String) As String
Returns the user's answer (to this question's option) on form 'FormIdName'; returns 'DefaultValue' if no answer was given

Function FormValues(ByVal QuestionIdName As String) As IList
Returns a set of phdcc.Data.View.ResultInfo results that the user answered for this question, ie use for checkboxes or radiobuttons question types

***Function FormXValues(ByVal FormIdName As String, ByVal QuestionIdName As String) As IList
Returns a set of phdcc.Data.View.ResultInfo results that the user answered for this question on form 'FormIdName', ie use for checkboxes or radiobuttons question types

Function SetShowBlankFormValues(ByVal ShowBlankFormValues As Boolean) As String
If set true, if no results were entered by the user then a debug string is returned

If the user did not answer a question, then Nothing is returned, unless you have specified a default value (or called SetShowBlankFormValues(True)).

The phdcc.Data.View.ResultInfo class has these properties:

The phdcc.Data.View.ResultSetInfo class has these properties:

More detailed VB example for a 'Profile' form

The following code shows how to use more of the phdcc.Form.View functions in VB. The code follows the rules given above: it does not use Response.Write, and it sets server control properties before the control is declared.

  1. The code first looks up the answer to the file question that asked for an image, question "id7PhotoPrimary" on form "idPhoto". If the user has uploaded a photo then the imgPrimaryPhoto server control source is set to the correct URL; otherwise the control is made not visible.
  2. The code then looks up the answers to the checkboxes question "idHelpType" on form "idProjectProfile". Each checked answer option is added to the blHelpType bulleted list server control.

<table>
<tr>
<td>
<%
  Dim PhotoPrimary As String = FormX("idPhoto", "id7PhotoPrimary")
  If Not PhotoPrimary Is Nothing Then
    imgPrimaryPhoto.ImageUrl = PhotoPrimary
  Else
    imgPrimaryPhoto.Visible = False
  End If
%>

<asp:Image ID="imgPrimaryPhoto" runat="server" Width="100%" />
</td>
<td>
<%
  For Each ri As ResultInfo In FormXValues("idProjectProfile", "idHelpType")
    blHelpType.Items.Add(ri.ResultValue)
  Next ri
%>

<asp:BulletedList ID="blHelpType" runat="server" />
</td>
</tr>
</table>