• Decrease Text SizeIncrease Text Size

Setup custom DataBind script for module designer search results (#2)

Posted Date: 5/23/2023
    Printer Friendly Version   Email A Friend   Add This   Increase Text Size   Decrease Text Size
In this example, you can create a Databind script to display additional Provider Locations.
It would need to be placed in Module Designer > Results View (#2) > Item Content


[cp:databind key='this.ModulePage.CpScripting.asp_SampleLocation(Container.DataItem, "<ul class=\"locations\">{0}</ul>", "PrivatePracticeLocations", false)' /]


This code will need to be placed into the custom cp:scripting file.


 public string asp_SampleLocation(object dataItem, string format, string locationType, bool buildLink = true)
        {
            if (String.IsNullOrEmpty(locationType)) return String.Empty;

            Guid dataId = (Guid)DataBinder.Eval(dataItem, "DataId");

            StringBuilder html = new StringBuilder();
            foreach (DataRow row in GetPhysiciansForLocations().Select($@"DataId = '{dataId}' AND AttributeSystemName = '{locationType.SqlEncode()}'"))
            {
                string url = this.Page.BuildUrl((int)row["AutoNumber"], (Guid)row["AttributeDataId"], row["Title"].ToString(), "Title", "find-a-location", this.Page.AudienceInfo.SystemName);
                string title = (string)row["Title"];
                string phone = (string)row["TextBox4"];

                html.Append("<li>");
                if (buildLink)
                    html.Append($"<div><a href=\"{url}\">{title}</a></div>");
                else
                    html.Append($"<div>{title}</div>");

                if (!String.IsNullOrEmpty(phone))
                    html.Append($"<div>{phone}</div>");

                html.Append("</li>");
            }

            if (html.Length > 0 && !String.IsNullOrEmpty(format))
            {
                return CpScripting.FormatStringDecode(String.Format(format, html.ToString()));
            }
            return html.ToString();
        }




  private DataTable GetPhysiciansForLocations()
        {
            string strKey = "GetPhysiciansForLocations";
            DataTable dt = CpCache.Get(strKey, false, false) as DataTable;
            if (dt == null)
            {
                string strSql = $@"
                SELECT DISTINCT cpsys_DataCurrentInDataCurrent.DataId, cpsys_DataCurrentInDataCurrent.AttributeSystemName, 
                cpsys_DataCurrentInDataCurrent.AttributeDataId,
                cprel_GenericEnhancedX.Title,
                cprel_GenericEnhancedX.AutoNumber,
                cprel_GenericEnhancedX.TextBox4
                FROM cpsys_DataCurrentInDataCurrent 
                INNER JOIN cprel_GenericEnhancedX ON cprel_GenericEnhancedX.DataId = cpsys_DataCurrentInDataCurrent.AttributeDataId 
                WHERE AttributeSystemName IN ('MainLocation', 'OtherLocation', 'PrivatePracticeLocations')
                ";

                dt = Utilities.Database.GetDataTable("cpsys_DataCurrentInDataCurrent", strSql, this.Page.SelectConnectionString);
                CpCache.Insert(strKey, dt, new string[] { "PhysicianDirectory" }, new string[] { }, false, false, false, false, false);
            }
            return dt;
        }

Keywords: DataBind, module designer, search results



Related Taxonomy
  - How Do I?
  - Questions

Comments:

Be the first to leave a comment.
Please Login to post comments.