Tom
|
Posted: 01/18/2006, 2:35 PM |
|
Figured it out. Maybe this will be useful for someone else.
I wanted to put my checkbox list in a table and do a new row for every 4 checkbox elements. The only way I could find to do that is if I decorated the checkbox {Description} with html. Adding "</td>" to every description, but every 4th description I would add "</td></tr><tr>" which would create a new row. And of course, if its the last checkbox, only add "</td>" even if it is divisable by 4.
One of the tricky things going on here is, taking the CheckBoxList options which came from the database, modifying the strings, then create a string that can be used in the setListOfValues method.
I did this because I couldn't find a way to directly modify the description in the CheckBoxList object. If it is possible to do so, I'm still interested in knowing how.
Here is the checkbox list html
<tr class="Controls">
<td colspan="2">
<table>
<tr>
<!-- BEGIN CheckBoxList tc_projects -->
<td><input type="checkbox" value="{Value}" name="{tc_projects_Name}" {Check}>{Description}<!-- END CheckBoxList tc_projects -->
</tr>
</table>
</td>
</tr>
Here is the Before Show event of the checkbox
Enumeration enum_tc_projects = ((CheckBoxList)e.getControl()).getFormattedOptions();
StringBuffer sb = new StringBuffer();
Integer optionnum = 0;
while ( enum_tc_projects.hasMoreElements() )
{
String[] option = (String[]) enum_tc_projects.nextElement();
optionnum++;
if(enum_tc_projects.hasMoreElements() && optionnum%4 == 0)
{
option[1] = option[1] + "</td></tr><tr>";
}
else
{
option[1] = option[1] + "</td>";
}
sb.append(option[0]).append(';').append(option[1]).append(';');
}
sb.deleteCharAt(sb.length()-1);
((CheckBoxList)e.getControl()).setListOfValues(sb.toString());
|