<%@ 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">
    <script type="text/javascript">
        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);
        }

        function RowDataBound(sender, args) {
            // manually set the hyperlink's title
            var item = args.get_item();
            var dataItem = args.get_dataItem();
            var link = item.get_cell("Name").getElementsByTagName("a")[0];
            link.innerHTML = dataItem.Name;
            link.href = dataItem.Name;

        }
    </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" AllowFilteringByColumn="true"
        AutoGenerateColumns="false" runat="server">
        <MasterTableView>
            <Columns>
                <telerik:GridTemplateColumn>
                    <ItemTemplate>
                        <asp:Label runat="server" ID="NameID"></asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn>
                    <ItemTemplate>
                        <asp:Label runat="server" ID="Name"></asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridHyperLinkColumn DataTextField="SurveyName" DataNavigateUrlFields="SurveyName"
                    UniqueName="Name" HeaderText="Name" ItemStyle-Font-Underline="true" />
                <telerik:GridNumericColumn DataField="UnitPrice" HeaderText="Unit price" DataType="System.Decimal" />
                <telerik:GridBoundColumn DataField="Date" DataFormatString="{0:d}" HeaderText="Date"
                    DataType="System.DateTime" />
                <telerik:GridCheckBoxColumn DataField="Discontinued" HeaderText="Discontinued" DataType="System.Boolean" />
            </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>
