Cycle de progression Faire (quelque chose qui marche) -> comprendre ce que l’on fait/comment cela marche -> pousser plus loin les notions
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebControlLibrary1 { [DefaultProperty("Items")] [ToolboxData("<{0}:CustomDropDownList runat=server></{0}:CustomDropDownList>")] public class CustomDropDownList : DropDownList { protected override void RenderContents(HtmlTextWriter output) { output.Write(BuildHtml()); } public String BuildHtml() { string result = string.Empty; bool selected = true; foreach (ListItem item in this.Items) if (selected) { result += "<option selected="selected" value="" + item.Value + "">" + item.Text + "</option>"; selected = false; } else result += "<option value="" + item.Value + "">" + item.Text + "</option>"; return result; } } } |
| <cc1:CustomDropDownList ID="CustomDropDownList1" runat="server"></cc1:CustomDropDownList> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head><title> Test customDropDownList </title></head> <body> <form name="form1" method="post" action="Default.aspx" id="form1"> <div> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTMyNDcyODMzOA9kFgICAw9kFgQCAQ8PFgIeBFRleHQFEzAxLzA4LzIwMDcgMjA6Mjc6NDJkZAIHDxBkDxYCZgIBFgIQBQdwcmVtaWVyBQdwcmVtaWVyZxAFBnNlY29uZAUGc2Vjb25kZxYBZmRkRjfX3GI5C/+nuCitxM8iYw/QSYw=" /> </div> <div> <span id="Label1">01/08/2007 20:27:42</span> <input name="TextBox1" type="text" value="second" id="TextBox1" /> <input type="submit" name="Button1" value="Button" id="Button1" /> <select name="CustomDropDownList1" id="CustomDropDownList1"> <option selected="selected" value="premier">premier</option><option value="second">second</option> </select> </div> <div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwKeqdrbDwLs0bLrBgKM54rGBid26Ir5YurgmN0Kn2uAx5BkSjfz" /> </div></form> </body> </html> |