Suppressing Blank Fields in an Address

Description

This example shows how to hide blank fields when displaying an address.

  1. Create a read-only tabular grid based on the Customer table of the AlphaSports sample database.

  2. Display the Grid > Fields page.

  3. Move the "Firstname", "Lastname", "Phone", "Bill_Address_1", "Bill_Address_2", "Bill_City", "Bill_State_Region", "Bill_Postal_Code", and "Bill_Country" fields from the Available Fields list to the Selected Fields list.

  4. Select the "Firstname" field in the Selected Fields list and set its Column Properties > Hide column property to "True".

  5. Select the "Lastname" field in the Selected Fields list:

    function LASTNAME_render as C (data as P, args as P, PageVars as P) 'do not delete this line
    with PageVars 'do not delete this lineon error goto LASTNAME_XbasicError 'do not delete this line
    LASTNAME_render = alltrim(data.Firstname) + " " + Alltrim(Data.LASTNAME)
    end
    
    'do not delete this line
    LASTNAME_XbasicError: 'do not delete this line
    LASTNAME_render = "Error in custom control Xbasic: " + error_text_get()'do not delete this line
    end with 'do not delete this line
    end function 'do not delete this line
    • Set its Display Settings > Control type property to "Custom".

    • Set its Column Properties> Control heading property to "Name".

    • Set its Column Properties> Heading in-line style property to "text-align: left;".

    • Click the '...' button in the Custom Control Properties > Definition property to display the Define Xbasic for Custom Control dialog.

    • Modify the code as follows and click OK.

  6. Select the "Phone" field in the Selected Fields list and set its Column Properties> Heading in-line style property to "text-align: left;".

  7. Select the "Bill_Address_1" field in the Selected Fields list:

    • Set its Display Settings > Control type property to "Custom".

    • Set its Column Properties> Control heading property to "Address".

    • Set its Column Properties> Heading in-line style property to "text-align: left;".

    • Click the '...' button in the Custom Control Properties > Definition property to display the Define Xbasic for Custom Control dialog.

    • Modify the code as follows and click OK.

      function BILL_ADDRESS_1_render as C (data as P, args as P, PageVars as P) 'do not delete this line
      with PageVars 'do not delete this line
      on error goto BILL_ADDRESS_1_XbasicError 'do not delete this line
      BILL_ADDRESS_1_render = remove_blank_linesData.BILL_ADDRESS_1) + crlf()+ alltrim(Data.BILL_ADDRESS_2) + crlf()+ alltrim(Data.BILL_CITY) + ", " + alltrim(Data.BILL_STATE_REGION) + " " + alltrim(Data.BILL_POSTAL_CODE) + crlf()+ alltrim(Data.BILL_country?
      BILL_ADDRESS_1_render = stritran(BILL_ADDRESS_1_render, crlf(), "<br>")
      end
      'do not delete this line
      BILL_ADDRESS_1_XbasicError: 'do not delete this line
      BILL_ADDRESS_1_render = "Error in custom control Xbasic: " + error_text_get()'do not delete this line
      end with 'do not delete this line
      end function 'do not delete this line
  8. Select the "Bill_Address_2", "Bill_City", "Bill_State_Region", "Bill_Postal_Code", and "Bill_Country" fields in the Selected Fields list and set their Column Properties > Hide column property to "True".

  9. Display the Grid > Properties page.

  10. Set the Layout Options > Style name to "Arizona".

  11. Set the Layout Options > Rows of data to 5.

  12. Set the Shading and Dividers > Alternate row shading to "True".

  13. Set the Customization > Row separator HTML to

    " <tr><td class="{a5_style}SeparatorTD" colspan="{a5_colspan}" style="padding: 0px;" ></td></tr> "
    This creates a white band that separates the rows.
  14. Save your work and click the Browser button. You should see something like this.