复制代码 代码如下:
 
<asp:CheckBoxList runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow"> <asp:ListItem Text="测试A" Value="A"></asp:ListItem> 
<asp:ListItem Text="测试B" Value="B"></asp:ListItem> 
<asp:ListItem Text="测试C" Value="C"></asp:ListItem> 
<asp:ListItem Text="测试D" Value="D"></asp:ListItem> 
<asp:ListItem Text="测试E" Value="E"></asp:ListItem> 
</asp:CheckBoxList> 
复制代码 代码如下:
 
[ToolboxData("<{0}:CheckBoxListEx runat=/"server/"></{0}:CheckBoxListEx>")] 
public class CheckBoxListEx : CheckBoxList,IRepeatInfoUser 
{ 
void IRepeatInfoUser.RenderItem(ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer) 
{ 
string clientID = UniqueID + this.ClientIDSeparator + repeatIndex.ToString(NumberFormatInfo.InvariantInfo); //var 
writer.WriteBeginTag("input"); 
writer.WriteAttribute("type", "checkbox"); 
writer.WriteAttribute("name", UniqueID + this.IdSeparator + repeatIndex.ToString(NumberFormatInfo.InvariantInfo)); 
writer.WriteAttribute("id", clientID); 
writer.WriteAttribute("value", Items[repeatIndex].Value); 
if (Items[repeatIndex].Selected) 
writer.WriteAttribute("checked", "checked"); 
System.Web.UI.AttributeCollection attrs = Items[repeatIndex].Attributes; 
foreach (string key in attrs.Keys) 
{ 
writer.WriteAttribute(key, attrs[key]); 
} 
writer.Write("/>"); 
writer.Write("<label for='" + clientID + "'>"); 
writer.Write(Items[repeatIndex].Text); 
writer.Write("</label>"); 
} 
复制代码 代码如下:
 
<script> 
function getDemoValue() 
{ var els = document.getElementById("chkDemo"); var vals= ''; if (els != null) { var chks = els.getElementsByTagName("input"); for (var k = 0, len = chks.length; k < len; k++) { var chk = chks[k]; if (chk != null && chk.type == 'checkbox' && chk.checked) { vals+= ',' + chk.value; } } } 
if(vals.length>1) 
vals = vals.substring(1); 
return vals; 
} 
</script> 
新闻热点
疑难解答
图片精选