public partial class Test : Page { protected override void OnInit(EventArgs e) { base.OnInit(e); ImageCheckBoxList chkList = new ImageCheckBoxList(); for (int i = 0; i < 10; i++) chkList.Items.Add(new ListItem("Item " + i) { Selected = i % 2 == 0 }); this.form1.Controls.Add(chkList); } } public class ImageCheckBoxList : CheckBoxList { public bool IsEditable { get; set; } public override void RenderControl(HtmlTextWriter writer) { if (this.IsEditable) base.RenderControl(writer); else { StringBuilder sb = new StringBuilder(); sb.Append("<table class=\"ImageCheckBoxList\">"); foreach (ListItem item in this.Items) { sb.Append("<tr>"); sb.AppendFormat("<td><img src=\"{0}\" alt=\"{1}Checked\" /></td>", ResolveUrl(string.Format("~/Images/{0}Checked.png", item.Selected ? string.Empty : "Not")), item.Selected ? string.Empty : "Not"); sb.AppendFormat("<td><label>{0}</label></td>", item.Text); sb.Append("</tr>"); } sb.Append("</table>"); writer.Write(sb.ToString()); } } }
Monday, July 26, 2010
How to build a readonly checkbox list - Asp.net
Subscribe to:
Post Comments (Atom)
Azure Storage Account Types
Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...
-
Why we need asynchronous tasks? Execute a time consuming operations in parallel to the CLR thread which execute the request If you have ...
-
Demo: I was thinking a way to show images before actually uploading them to server. I would say to preview images using javascript. Obv...
No comments:
Post a Comment