Spotlight IT Ramblings Blog

I'm living in Dublin, Ireland and this is a collection of ramblings about my day-to-day activities in the exciting world of web development ;-) Technologies used and projects under development. Also links of interest, mostly completely work un-related....

Tuesday, February 27, 2007

ASP.Net Adapters to modify control display

I came across a requirement on a project I am working on recently where they
wanted a Dropdownlist control to show "option groups" so that the items are
categorised i.e. produce something like this output when the data is bound
to the control.

<select>
<option value="" class="none" selected="selected">Any</option>
<optgroup label="County Clare">
<option value="" class="none">Ardnacrusha</option>
<option value="" class="none">Killaloe</option>
<option value="" class="none">Tulla</option>
<option value="" class="none">West Clare</option>
</optgroup>
<optgroup label="County Kerry">
<option value="" class="none">Ballybunion</option>
<option value="" class="none">Causeway</option>
<option value="" class="none">Kenmare</option>
<option value="" class="none">Listowel</option>
<option value="" class="none">Tralee</option>
</optgroup>
<optgroup label="County Tipperary">
<option value="" class="none">Birdhill</option>
<option value="" class="none">Nenagh</option>
<option value="" class="none">Newport</option>
<option value="" class="none">Thurles</option>
</optgroup>
<optgroup label="Limerick City">
<option value="" class="none">Annacotty</option>
<option value="" class="none">Aspen Gardens</option>
<option value="" class="none">Athlunkard Street</option>
<option value="" class="none">Ballinacurra</option>
</optgroup>
</select>

The main problem is that ASP.Net 2.0 does not support these option groups.

Data Adapters to the rescue. You can modify how a control is rendered (even
down to individual browsers (IE Vs Mozilla etc.) by applying a custom
attribute to the control. These attributes are then picked up in the adapter
code and modify the control's output to include the optgroup elements

If anyone wants the full code please let me know...

0 Comments:

Post a Comment

<< Home

 

Valid CSS!
news section


news seperator