<%@ Page Language="c#" Inherits="Telerik.GridExamplesCSharp.Client.DeclarativeDataBinding.DefaultCS"
    CodeFile="DefaultCS1.aspx.cs" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">

        var firstCell = null;

        function RowDataBound(sender, args) {

            var item = args.get_item();
            if (item._itemIndexHierarchical == 0) {
                if (firstCell != null) {
                    firstCell = null;
                }
                else {
                    firstCell = args.get_item().get_cell("Template");
                }
            }
            else {
                firstCell.innerHTML = firstCell.innerHTML + item.get_cell("Template").innerHTML;
                if (item._itemIndexHierarchical % 4 == 0) {
                    firstCell.innerHTML = firstCell.innerHTML;
                }
                item.set_visible(false);
            }
        }

        function RadGrid1_DataBinding(sender, args) {
            // This event will be raised twice by default! 
            // The first call will retrieve data and the second call will retrieve total items count.
            // If you want to cancel the event you can use:
            // args.set_cancel(true);

            // get data source location, method name and arguments
            var dataSourceLocation = args.get_location();
            var selectMethodName = args.get_methodName();
            var methodArguments = args.get_methodArguments();

            // set data source location and method name
            // args.set_location("url to your data source");
            // args.set_methodName("your method name");

            // The grid will always pass by default four arguments for the SelectMethod.
            // SelectCountMethod will be called with no arguments by default!

            // get names for select parameters
            var startRowIndexParameterName = sender.ClientSettings.DataBinding.StartRowIndexParameterName;
            // default is "startRowIndex". 

            var maximumRowsParameterName = sender.ClientSettings.DataBinding.MaximumRowsParameterName;
            // default is "maximumRows"

            var sortParameterName = sender.ClientSettings.DataBinding.SortParameterName;
            // default is "sortExpression"

            var filterParameterName = sender.ClientSettings.DataBinding.FilterParameterName;
            // default is "filterExpression"

            // construct your own arguments
            // var myMethodArguments = new Object();
            // myMethodArguments.myArgumentName = "myArgumentValue";
            // args.set_methodArguments(myMethodArguments);
        }
    </script>
</head>
<body class="BODY">
    <form runat="server" id="mainForm" method="post">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <telerik:RadGrid ID="RadGrid1" AllowSorting="true" AllowPaging="true" PageSize="8"
        Width="1000px" AllowFilteringByColumn="true" AutoGenerateColumns="false" runat="server">
        <MasterTableView TableLayout="Fixed">
            <Columns>
                <telerik:GridTemplateColumn UniqueName="Template">
                    <ItemTemplate>
                        <asp:Panel ID="ItemContainer" CssClass='<%# (((GridItem)Container).ItemType == GridItemType.Item)? "item" : "alternatingItem" %>'
                            runat="server">
                            <asp:Label runat="server" ID="Name"></asp:Label>
                            <br />
                            <b>Price:</b>
                            <asp:Label runat="server" ID="UnitPrice"></asp:Label>
                        </asp:Panel>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
        <PagerStyle AlwaysVisible="true" />
        <ClientSettings>
            <DataBinding Location="WebService.asmx" SelectMethod="GetData" SelectCountMethod="GetCount" />
            <ClientEvents OnDataBinding="RadGrid1_DataBinding" OnRowDataBound="RowDataBound" />
        </ClientSettings>
    </telerik:RadGrid>
    </form>
</body>
</html>
