<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Download.aspx.cs" Inherits="Download" %>

<%@ 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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
    <div>
        <telerik:RadGrid ID="RadGrid1" runat="server" Skin="Vista" GridLines="None"            
            OnNeedDataSource="RadGrid1_NeedDataSource">
            <MasterTableView ClientDataKeyNames="Files"></MasterTableView>
            <ClientSettings>
                <ClientEvents OnRowContextMenu="onRowContextMenu" />
                <Selecting AllowRowSelect="True" />
            </ClientSettings>
        </telerik:RadGrid>
<input type="hidden" id="radGridClickedRowIndex" runat="server" name="radGridClickedRowIndex" />        
    </div>
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript">
function onRowContextMenu(sender, eventArgs)
{
    var menu = $find("<%=RadContextMenu1.ClientID %>");
    var evt = eventArgs.get_domEvent();
    
    if(evt.target.tagName == "INPUT" || evt.target.tagName == "A")
    {
      return;
    }
    
    var index = eventArgs.get_itemIndexHierarchical();
    $get("radGridClickedRowIndex").value = index;
    
    sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);
    
    menu.show(evt);
    
    evt.cancelBubble = true;
    evt.returnValue = false;

    if (evt.stopPropagation)
    {
       evt.stopPropagation();
       evt.preventDefault();
    }
}

function onClientMenuItemClicked(sender, e)
{
    if (e.get_item().get_text() == "Download")
    {
        var masterTable = $find("<%=RadGrid1.ClientID %>").get_masterTableView();
        var dataItem = masterTable.get_dataItems()[$get("radGridClickedRowIndex").value];
        var file = dataItem.getDataKeyValue("Files");  
        window.open(file);
    }
}   
</script>
</telerik:RadScriptBlock>    
    
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadContextMenu ID="RadContextMenu1" runat="server" OnClientItemClicked="onClientMenuItemClicked"
            Skin="Vista">
            <Items>
                <telerik:RadMenuItem runat="server" Text="Download">
                </telerik:RadMenuItem>
                <telerik:RadMenuItem runat="server" Text="Edit">
                </telerik:RadMenuItem>
                <telerik:RadMenuItem runat="server" Text="Delete">
                </telerik:RadMenuItem>
            </Items>
        </telerik:RadContextMenu>
    </form>
</body>
</html>
