<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Telerik.RadTips._Default" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Example - Enabling Client-Side Selection of Items in the RadGrid for ASP.NET AJAX</title>
</head>
<body>
    <form id="form1" runat="server">
		<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
			<Services>
				<asp:ServiceReference Path="~/Services/NorthwindService.asmx" />
			</Services>
		</telerik:RadScriptManager>
		
		<telerik:RadGrid ID="RadGrid1" runat="server" 
			AllowPaging="True" AllowMultiRowSelection="true"
			AutoGenerateColumns="False" 
			PageSize="10">
			<MasterTableView ClientDataKeyNames="CustomerID">
				<Columns>
					<telerik:GridBoundColumn 
						DataField="CompanyName"
						HeaderText="Customer">
					</telerik:GridBoundColumn>
					<telerik:GridBoundColumn 
						DataField="Country"
						HeaderText="Location">
					</telerik:GridBoundColumn>
				</Columns>
			</MasterTableView>
			<ClientSettings>
				<ClientEvents OnRowSelected="RadGrid1_RowSelected" />
				<DataBinding				
					CountPropertyName="CustomerCount"
					DataPropertyName="Customers"	
					Location="Services/NorthwindService.asmx"
					MaximumRowsParameterName="rowCount"
					SelectMethod="GetCustomers"
					StartRowIndexParameterName="startIndex">
				</DataBinding>
				<Selecting AllowRowSelect="true" />				
			</ClientSettings>
		</telerik:RadGrid>
		
		<telerik:RadGrid ID="RadGrid2" runat="server"
			OnNeedDataSource="RadGrid2_NeedDataSource"
			style="display: none;">
			<MasterTableView>
				<Columns>
					<telerik:GridBoundColumn 
						DataField="OrderDate"
						HeaderText="Date">
					</telerik:GridBoundColumn>
					<telerik:GridBoundColumn 
						DataField="Quantity"
						HeaderText="Quantity Purchased">
					</telerik:GridBoundColumn>
					<telerik:GridBoundColumn 
						DataField="Price"
						DataFormatString="{0:c}"
						HeaderText="Sell Price">
					</telerik:GridBoundColumn>
					<telerik:GridBoundColumn 
						DataField="Destination"
						HeaderText="Destination">
					</telerik:GridBoundColumn>
				</Columns>
			</MasterTableView>
		</telerik:RadGrid>
		
		<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
			<script type="text/javascript">
				function RadGrid1_RowSelected(sender, args) {
					var tableView = args.get_tableView();
					var dataItems = tableView.get_selectedItems(); //[0].get_dataItem();
					var customerIDs = new Array();
					for (i = 0; i < dataItems.length; i++) {
						customerIDs.push(dataItems[i].getDataKeyValue("CustomerID"));
					}
					Telerik.RadTips.NorthwindService.GetOrders(customerIDs, getOrdersCompleted, getOrdersFailed);
				}

				function getOrdersCompleted(result) {
					var gridElement = $get('<%= RadGrid2.ClientID %>');
					var tableView = $find('<%= RadGrid2.ClientID %>').get_masterTableView();
					gridElement.style.display = "block";
					tableView.set_dataSource(result.Orders);
					tableView.dataBind();
				}

				function getOrdersFailed(error) {
					alert(error.get_message());
				}
			</script>
		</telerik:RadCodeBlock>
    </form>
</body>
</html>
