[C#] Ajout d'une méthode à la classe DropDownList
Bonjour, est ce que qqn sait comment ajouter une méthode à la classe DropDownList ?
Voila la méthode à ajouter:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| protected override void RenderContents(HtmlTextWriter writer)
{
if (Items != null)
{
bool selected = false;
foreach (ListItem listItem in Items)
{
writer.WriteBeginTag("option");
if (listItem.Selected)
{
if (selected)
//throw new HttpException(HttpRuntime.FormatResourceString("Cannot_Multiselect_In_DropDownList"));
throw new HttpException("Cannot multiselect in DropDownList."); //TODO: this should be language independent
selected = true;
writer.WriteAttribute("selected", "selected", false);
}
writer.WriteAttribute("value", listItem.Value, true);
listItem.Attributes.Render(writer); // This is the added code
//TODO: What happens if "value" or "selected" are in listItem.Attributes?
writer.Write('>');
HttpUtility.HtmlEncode(listItem.Text, writer);
writer.WriteEndTag("option");
writer.WriteLine();
}
}
} |