Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > A "fix" for CheckBoxLists in the MyProfile webpart View modes: 
User avatar
Guest
Internet Geeks - 7/31/2009 9:24:57 AM
   
A "fix" for CheckBoxLists in the MyProfile webpart
Hello,

I thought I'd share a rather useful code snippet with you all.

We had a situation where we'd added a number of multiple select fields to the Users table and wanted to display this using the MyProfile webpart. Unfortunately each field contained rather a lot of options and when it came to display these it broken the design of our website (because the WebPart build these options using a CheckBoxList).

To stop this WebPart from rendering CheckBoxLists in tables you can modify the file ~/CMSModules/Membership/Controls/MyProfile.ascx.cs. Replace the existing OnPreRender method with the following:

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
editProfileForm.BasicForm.SubmitButton.CssClass = "ContentButton";

foreach (object c in editProfileForm.BasicForm.FindControl("pnlForm").Controls)
{
if (c is CMS.FormControls.EditingFormControl)
{
CMS.FormControls.EditingFormControl efc = (CMS.FormControls.EditingFormControl)c;
if (efc.NestedControl is CheckBoxList)
{
CheckBoxList cbl = (CheckBoxList)efc.NestedControl;
cbl.RepeatLayout = RepeatLayout.Flow;
cbl.RepeatDirection = RepeatDirection.Horizontal; // This removes the "random" BR thats placed after each checkbox
}

}
}
}

Now any fields multiple select fields that you add will be rendered next to each other without using an HTML table.

I hope this helps.
Regards,