ToggleButtonExtender可以直接與單一的CheckBox結合,以圖片來代表傳統勾選介面的方式。
但碰到CheckBoxList時卻無法將ToggleButtonExtender的TargetControlID設為CheckBoxList控制項ID,這時需要自行撰寫JavaScript
- <script src="jquery-1.3.2.JS" type="text/Javascript"></script>
- <script type="text/Javascript">
- $(function() {
- var CheckedImageAlternateText = "Good";
- var CheckedImageUrl = "images/ToggleButton_Checked.gif";
- var ImageHeight = 20;
- var ImageWidth = 20;
- var UncheckedImageAlternateText = "shit";
- var UncheckedImageUrl = "images/ToggleButton_unChecked.gif";
- var tid = "CheckBox1_ToggleButtonExtender";
- $("#CheckBoxList1 :checkbox").each(function(index) {
- $create(AJaxControlToolkit.ToggleButtonBehavior, { "CheckedImageAlternateText": CheckedImageAlternateText, "CheckedImageUrl": CheckedImageUrl,
- "ImageHeight": ImageHeight, "ImageWidth": ImageWidth, "UncheckedImageAlternateText": UncheckedImageAlternateText,
- "UncheckedImageUrl": UncheckedImageUrl, "id": tid + index.toString() }, null, null, $get(this.id));
- });
- });
- </script>