Please enable JavaScript to view this site.

Navigation: Using ASPRunner.NET > Page Designer > "View as" settings

Custom

Scroll Prev Next More

 

You can format field values by adding C#/VB.NET code.

view_as_custom_net

The input value is stored in the variable value. The output value is assigned to the same variable value. You can access other fields of the same data record as data["FieldName"].

 

If you chose Lookup wizard in the "Edit as" settings, use value to access the Display field value and data["LinkFieldName"] to access the Link field value.

Examples

1. Convert a string into the upper case:

 

value = MVCFunctions.strtoupper(value);

 

2. Format a 10-digit phone number into the following format (xxx) xxx-xxx:

 

if(value.Length() == 10)
{
  value = String.Format("({0}){1}-{2}", value.Substring(0,3), value.Substring(3,3), value.Substring(6));
}

 

3. Display the value of the field FirstName as <FirstName> <LastName> (if the LastName field defined):

 

if(data["LastName"] != null)
{
  value = MVCFunctions.Concat(value, " ", data["LastName"]);
}

 

4. Display a number in black if the number is positive, and in red if the number is negative:

 

XVar color;
if(value > 0)
  color = "black";
else
  color = "red";
value = MVCFunctions.Concat("<font color='", color, "'>", value, "</font>");

 

5. Display a field containing email address as an email hyperlink (mailto function used). The value of subject in mailto function is set to a value of another field:

 

value = MVCFunctions.Concat("<a href='mailto:", value, "?subject=", data["SubjectField"], "'>Send email</a>");

 

6. Display a field value in one line (without line breaks):

 

value = value.Replace(" ", "&nbsp;");

 

7. Display all images uploaded via multiupload:

 

if(value.Length() > 0)
{
  var filesArray = MVCFunctions.my_json_decode(value);
  if(filesArray.IsArray())
  {
    var imageValue = new StringBuilder();
    foreach(var item in filesArray.GetEnumerator())
    {
        imageValue.Append("<img alt='");
        imageValue.Append(MVCFunctions.runner_htmlspecialchars(item.Value["usrName"]).ToString());
        imageValue.Append("' src=");            
        var fileName = MVCFunctions.runner_htmlspecialchars(item.Value["name"]);
        imageValue.Append(MVCFunctions.GetRootPathForResources(fileName).ToString());
        imageValue.Append(">");
    }
    value = imageValue.ToString();
  }
}

 

view_as_custom_ex

8. Display a phone number as a click-to-call link for mobile browsers:

 

value = MVCFunctions.Concat("<a href='tel:", value, "'>Call us!</a>");

See also:

Conditional formatting

How to create a custom Edit control plugin

"View as" settings

About Page Designer

About Editor