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

TSQL / SQL Calculating Cumulative Total

Calculating a moving cumulative total using TSQL statement.

The OVER clause defines a window or user-specified set of rows within a query result set. A window function then computes a value for each row in the window. 
You can use the OVER clause with functions to compute aggregated values such as moving averages, cumulative aggregates, running totals, or a top N per group results.


SELECT BusinessEntityID, TerritoryID 
   ,DATEPART(yy,ModifiedDate) AS SalesYear
   ,CONVERT(varchar(20),SalesYTD,1) AS  SalesYTD
   ,CONVERT(varchar(20),AVG(SalesYTD) OVER (PARTITION BY TerritoryID 
                                            ORDER BY DATEPART(yy,ModifiedDate) 
                                           ),1) AS MovingAvg
   ,CONVERT(varchar(20),SUM(SalesYTD) OVER (PARTITION BY TerritoryID 
                                            ORDER BY DATEPART(yy,ModifiedDate) 
                                            ),1) AS CumulativeTotal
FROM Sales.SalesPerson
WHERE TerritoryID IS NULL OR TerritoryID < 5
ORDER BY TerritoryID,SalesYear;

--
Jagadeesan Kandasamy