1。aspx代码:
<head runat="server">
<%=sb %>
</head>
<asp:CheckBoxList ID="chbList" runat="server"></asp:CheckBoxList>
2。aspx.cs
protected StringBuilder sb = new StringBuilder();
protected void Page_Load(object sender, EventArgs e)
{
if (chbList.Items.Count > 0)
{
sb.AppendLine("<style type='text/css'>");
for (int i = 0; i < chbList.Items.Count; i++)
{
sb.AppendLine("#chbList_" + i + "{width:30px; height:30px;padding: 5 5 5 0;} ");
}
sb.AppendLine("</style>");
}
}
3。CheckBoxList生成的html,查找<input id="chbList_0"
<table id="chbList" class="STYLE2" cellspacing="5" cellpadding="5" border="0" style="zoom: 100%">
<tr>
<td><input id="chbList_0" type="checkbox" name="chbList$0" /><label for="chbList_0">aaaa</label></td>
</tr><tr>
<td><input id="chbList_1" type="checkbox" name="chbList$1" /><label for="chbList_1">BBBB</label></td>
</tr><tr>
<td><input id="chbList_2" type="checkbox" name="chbList$2" /><label for="chbList_2">CCCC</label></td>
</tr><tr>
<td><input id="chbList_3" type="checkbox" name="chbList$3" /><label for="chbList_3">DDDD</label></td>
</tr><tr>
<td><input id="chbList_4" type="checkbox" name="chbList$4" /><label for="chbList_4">EEEE</label></td>
</tr>
</table>