Friday, September 28, 2012

RadListBox - Multi Select With Select All Option

This article will show you how to have an item which checks/unchecks all items. 

Select All  OR Un Select All  - sing Rad Combo / List Box Control

The aspx File

<script language="javascript" type="text/javascript">
    function OnClientItemChecked(sender, eventArgs) {
        var lstBoxControl;
        lstBoxControl = $find(sender.get_id());
        var items = lstBoxControl.get_items();
        if (eventArgs.get_item().get_index() == 0) {
            var firstIndex = eventArgs.get_item().get_checked();
            for (var i = 0; i < lstBoxControl.get_items().get_count(); i++) {

                items.getItem(i).set_checked(firstIndex);
            }
        }
        else {
            items.getItem(0).set_checked(false);
        }
    }
</script>

<telerik:RadListBox AppendDataBoundItems="true" TabIndex="1" Width="200px" CheckBoxes="true" ID="lstClassificationTypes" DataSourceID="dataClassificationTypes" runat="server" DataTextField="SelectionName" DataValueField="SelectionId" OnClientItemChecked="OnClientItemChecked">
<Items>
<telerik:RadListBoxItem Text="Select / UnSelect All" Value=0 BackColor=Gray Font-Bold="true" ForeColor=White />
</Items>
</telerik:RadListBox> 


The aspx.cs File

Find Selected Item

protected void btnGenerate_Click(object sender, EventArgs e)
    {
        StringBuilder sb = new StringBuilder();
        IList<RadListBoxItem> collection = ((RadListBox)fview.FindControl("lstClassificationTypes")).CheckedItems;

        foreach (RadListBoxItem item in collection)
        {
            // Your Code Here >> item.Value
        }
    }

If you need additional assistance, do not hesitate to contact me.@ tkjagadheesh@gmail.com

Regards,
JAG

Tags: RadListBox, C#, CheckBox, Java Script, Multiple Items, ASP.NET, AJAX, Rad Controls check all, Un check all, Select all, Multi Select Combo, MultiSelect List Box

No comments:

Post a Comment