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

<!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></title>
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <%--Needed for JavaScript IntelliSense in VS2010--%>
            <%--For VS2008 replace RadScriptManager with ScriptManager--%>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            var uploadedFilesCount = 0;
            var isEditMode;
            function validateRadUpload(source, e) {
                debugger;
                // When the RadGrid is in Edit mode the user is not obliged to upload file.
                if (isEditMode == null || isEditMode == undefined) {
                    e.IsValid = false;

                    if (uploadedFilesCount > 0) {
                        e.IsValid = true;
                    }
                }
                isEditMode = null;
            }

            function OnClientFileUploaded(sender, eventArgs) {
                uploadedFilesCount++;
            }
            
        </script>
    </telerik:RadCodeBlock>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
    <telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" Width="97%" ShowStatusBar="True" GridLines="None"
        OnItemCreated="RadGrid1_ItemCreated" PageSize="3" OnInsertCommand="RadGrid1_InsertCommand"
        OnNeedDataSource="RadGrid1_NeedDataSource" OnDeleteCommand="RadGrid1_DeleteCommand"
        OnUpdateCommand="RadGrid1_UpdateCommand" OnItemCommand="RadGrid1_ItemCommand">
        <PagerStyle Mode="NumericPages" AlwaysVisible="true" />
        <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="ID">
        <CommandItemSettings ShowExportToPdfButton="true" />
            <Columns>
                <telerik:GridEditCommandColumn ButtonType="ImageButton">
                    <HeaderStyle Width="3%" />
                </telerik:GridEditCommandColumn>
                <telerik:GridTemplateColumn HeaderText="Image Name" UniqueName="ImageName" SortExpression="Name">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="lblName" Text='<%# Eval("Name") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadTextBox runat="server" Width="200px" ID="txbName" Text='<%# Eval("Name") %>' />
                        <asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" ControlToValidate="txbName"
                            ErrorMessage="Please, enter a name!" Display="Dynamic" SetFocusOnError="true" />
                    </EditItemTemplate>
                    <HeaderStyle Width="30%" />
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Description" UniqueName="Description" DataField="Description">
                    <ItemTemplate>
                        <asp:Label ID="lblDescription" runat="server" Text='<%# TrimDescription(Eval("Description") as string) %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadTextBox ID="txbDescription" Width="300px" runat="server" TextMode="MultiLine"
                            Text='<%# Eval("Description") %>' Height="150px" />
                    </EditItemTemplate>
                    <ItemStyle VerticalAlign="Top" />
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn DataField="Data" HeaderText="Image" UniqueName="Upload">
                    <ItemTemplate>
                        <telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" DataValue='<%#Eval("Data") %>'
                            AutoAdjustImageControlSize="false" Height="80px" Width="80px" ToolTip='<%#Eval("Name", "Photo of {0}") %>'
                            AlternateText='<%#Eval("Name", "Photo of {0}") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadAsyncUpload runat="server" ID="AsyncUpload1" OnClientFileUploaded="OnClientFileUploaded"
                            AllowedFileExtensions="jpg,jpeg,png,gif" MaxFileSize="1048576" OnValidatingFile="RadAsyncUpload1_ValidatingFile">
                        </telerik:RadAsyncUpload>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton">
                    <HeaderStyle Width="2%" />
                </telerik:GridButtonColumn>
            </Columns>
            <EditFormSettings>
                <EditColumn ButtonType="ImageButton" />
            </EditFormSettings>
            <PagerStyle AlwaysVisible="True" />
        </MasterTableView>
    </telerik:RadGrid>
    </form>
</body>
</html>
