Sayfada yer alan bir CheckedBox List nesnesi üzerinde seçilen değerleri JavaScript tarafında almanız gerekebilir. Bu durumda da aşağıda paylaştığım kod işinize yarayabilir.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="CheckedListBox.Test" %>
<!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>CheckedListBox Test</title>
<script type="text/javascript">
function GetSelect() {
var checkList1 = document.getElementById('<%= chkList1.ClientID %>');
var checkBoxList1 = checkList1.getElementsByTagName("input");
var checkBoxSelectedItems1 = new Array();
for (var i = 0; i < checkBoxList1.length; i++) {
if (checkBoxList1[i].checked) {
checkBoxSelectedItems1.push(checkBoxList1[i].value);
}
}
var liste = checkBoxSelectedItems1;
alert('Seçilenler -> ' + liste);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="chkList1" runat="server">
<asp:ListItem Value="1">Test1</asp:ListItem>
<asp:ListItem Value="2">Deneme</asp:ListItem>
<asp:ListItem Value="3">Tttttt</asp:ListItem>
<asp:ListItem Value="4">Vvvvvv</asp:ListItem>
<asp:ListItem Value="5">Gggggg</asp:ListItem>
</asp:CheckBoxList>
<br/>
<asp:Button ID="btnTest" runat="server" Text="Neler seçilmiş ???" OnClientClick="return GetSelect();"/>
</div>
</form>
</body>
</html>