Click here to Skip to main content
15,914,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a checkboxlist with 5 items as 1]Select All 2]A 3]B 4]C 5]D
When i click on "select all" rest of the items A,B,C,D should be selected and
if i try to unselect checkbox B then the "select all" checkbox should be uncheched.
Note:Without making use of another checkbox and button. Is anything possible only with a single checkboxlist that will cover all requirements..... for asp.net application.
Posted
Updated 7-Nov-12 5:07am
v2

 
Share this answer
 
SQL
Dim i As String = checkbox1.SelectedValue
Dim index As Integer = 0

    If i <> "" Then
          index = Convert.ToInt16(CheckBoxList1.SelectedValue)
       End If

 if index = 1 Then

' index of select all checkbox '

   checkbox1.Items(2).checked = False
   checkbox1.Items(3).checked = False
   checkbox1.Items(4).checked = False

Else

   checkbox1.Items(2).checked = True
   checkbox1.Items(3).checked = True
   checkbox1.Items(4).checked = True

End If
End Sub




This what you mean???
 
Share this answer
 
v2
You can check this jquery implementation


JavaScript
<script type="text/javascript">

        $(document).ready(function () {
            $("input[id*='CheckBoxList1']").click(function (e) {
                var currentId = $(this);
                if (currentId.val() == "select all") {
                    $("input[id*='CheckBoxList1']").each(function () {
                        if ($(this).val() != "select all")
                            $(this).attr("checked", true);
                    });
                }
                else {
                    $("input[id*='CheckBoxList1'][value*='select all']").attr("checked", false);
                }              
            });

        });
    
    
    </script>



ASP.NET
<div>
        <asp:checkboxlist id="CheckBoxList1" runat="server" xmlns:asp="#unknown">
            <asp:listitem>select all</asp:listitem>
            <asp:listitem>a</asp:listitem>
            <asp:listitem>b</asp:listitem>
            <asp:listitem>c</asp:listitem>
            <asp:listitem>d</asp:listitem>
        </asp:checkboxlist>
    </div>
 
Share this answer
 
i have solved this from 1 link which i dont remember... but it helped me to solve my solution and i thank for that link....

using javascript for asp controls...

<script type="text/javascript">
function all()
{
if(document.getElementByid('chkall').checked==true)
{
document.getElementByid(chkA).checked=true;
document.getElementByid(chkB).checked=true;

}
else
{
document.getElementByid(chkA).checked=false;
document.getElementByid(chkB).checked=false;
}
}

function forA()
{
if(document.getElementByid('chkA').checked==false)
{
document.getElementByid('chkall').checked=false;
}
}

---same for checkbox B----

</script>

at your source for checkbox id=checkboxall write onclick="all()"---this will call function

and for id=checkboxA write onclick="forA()"

and so on
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900