[3.5] Surcharge du rendu d'un RadioButtonList
Salut,
N'étant pas convaincu par le rendu des RadioButtonList et CheckBoxList en mode flow et surtout layout j'aimerais créer un contrôle personnalisé pour chacun d'eux.
En fait, j'aimerais intégrer les boutons radio dans une liste non ordonnée (<ul>).
Le rendu proposé étant :
Code:
1 2
| <input id="Case1" type="checkbox" name="Case" />
<label for="Case1">Case 1</label> |
J'aimerais obtenir :
Code:
1 2 3 4 5 6 7
| <ul>
<li>
<input id="Case1" type="checkbox" name="Case" />
<label for="Case1">Case 1</label>
</li>
....
</ul> |
Or je n'arrive pas à retourner les checkbox dans la méthode Render! Voici une tentative simple et infructueuse :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| Public Class RadioButtonList
Inherits System.Web.UI.WebControls.RadioButtonList
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
writer.RenderBeginTag(HtmlTextWriterTag.Ul)
For Each item As ListItem In Me.Items
writer.RenderBeginTag(HtmlTextWriterTag.Li)
writer.Write(item)
writer.RenderEndTag()
Next
writer.RenderEndTag()
'MyBase.Render(writer)
End Sub
End Class |
J'ai beau chercher, lire la documentation msdn, quelque chose me manque!
Pour une page aspx :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <%@ Page Language="VB" AutoEventWireup="false" CodeFile="radioButtonList.aspx.vb" Inherits="ControleSurcharge_radioButtonList" %>
<%@ Register Assembly="Bibliotheque" Namespace="Bibliotheque.Controls" TagPrefix="im" %>
<!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 runat="server">
<title>Page sans titre</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<im:RadioButtonList ID="test" runat="server">
<asp:ListItem Value="0" Text="0"></asp:ListItem>
<asp:ListItem Value="1" Text="1"></asp:ListItem>
<asp:ListItem Value="2" Text="2"></asp:ListItem>
</im:RadioButtonList>
</div>
</form>
</body>
</html> |
J'ai en retour :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <!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>Page sans titre</title>
</head>
<body>
<form name="form1" method="post" action="radiobuttonlist.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTYxODA3MDMyMQ9kFgICAw9kFgICAQ8QZGQWAGRkPuFMu4QtKDopHNzWNTnykQm8lQA=" />
</div>
<div>
<ul>
<li>0</li><li>1</li><li>2</li>
</ul>
</div>
</form>
</body>
</html> |
Qui est le contenu des ListItem, mais donc visiblement pas des boutons radio.
Saurez-vous m'aider?
Merci par avance.