以下のコードを試してください:
解決策-1チェックボックスをオン
にするたびに、チェックボックスでチェックされたアイテムの値がアラートに表示されます。
Javascript コード :
< script type="text/javascript">
function itemClick(radioButton) {
var Control;
var selectedItems;
selectedItems = '';
Control = document.getElementById("<%=ckbList2DesignationUc.ClientID %>").getElementsByTagName("input");
for (var i = 0; i < Control.length; i++) {
if (Control[i].checked == true)
selectedItems += i.toString()+',';
}
alert(selectedItems);
}
</script>
ASPX コード :
protected void Page_Load(object sender, EventArgs e)
{
for (int index = 0; index < 10; index++)
{
ckbList2DesignationUc.Items.Add(new ListItem("Item" + index, index.ToString()));
}
foreach (ListItem Li in ckbList2DesignationUc.Items)
{
Li.Attributes.Add("onclick", "return itemClick()");
}
}
Jquery を使用して必要なソリューション:
ソリューション-2
< script type="text/javascript">
$(document).ready(function () {
var selectedCheckBoxes = '';
$('#ckbList2DesignationUc').each(function () {
var items = new Array();
$(this).find("input:checkbox").each(function () {
$(this).click(function () {
selectedCheckBoxes += $(this).val() + ",";
alert(selectedCheckBoxes);
});
});
});
});
< /script>
< asp:CheckBoxList ID="ckbList2DesignationUc" runat="Server" RepeatLayout="Flow" RepeatDirection="Horizontal" Width="100%">
< /asp:CheckBoxList>