Saturday, January 21, 2012

Single selection Checkbox list using JQuery +Asp.net

//CheckboxList Single selection using jquery
$(document).ready(function(){
var checkboxes = $('#<%=chkCategory.ClientID %>').find('input:checkbox');
checkboxes.click(function() {
    var selectedIndex = checkboxes.index($(this));
   
    var items = $('#<% = chkCategory.ClientID %> input:checkbox');
    for(i=0;i<items.length;i++)
    {
        if(i==selectedIndex)
         items[i].checked=true;
        else
        items[i].checked=false;
    }
});
});

.Aspx
===============================================================================


<asp:CheckBoxList ID="chkCategory" runat="server" RepeatLayout=Flow  RepeatDirection="Horizontal" Width="99%">
    <asp:ListItem Text="SC" Value="SC" Selected="True"></asp:ListItem>
    <asp:ListItem Text="ST" Value="ST"></asp:ListItem>
    <asp:ListItem Text="OBC" Value="OBC"></asp:ListItem>
    <asp:ListItem Text="Original Villagers of Noida" Value="Original Villagers of Noida"></asp:ListItem>
    <asp:ListItem Text="Employee of Noida Authority/Entrepreneur" Value="Employee of Noida Authority / Entrepreneur"></asp:ListItem>
    <asp:ListItem Text="Others" Value="Others"></asp:ListItem>
</asp:CheckBoxList>





Thanks
Alok Kumar Sharma 

No comments:

Post a Comment