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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>

        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
                var uploadedFilesCount = 0;
                var isEditMode;
                function validateRadUpload(source, e) {
                    // 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" EnableAJAX="false">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <div>
            <telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="True"
                AutoGenerateColumns="False" 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"></PagerStyle>
                <MasterTableView Width="2000px" CommandItemDisplay="Top" DataKeyNames="ID" EditMode="InPlace">
                    <Columns>
                        <telerik:GridEditCommandColumn ButtonType="ImageButton">
                            <HeaderStyle Width="36px"></HeaderStyle>
                        </telerik:GridEditCommandColumn>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name1"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name2"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name3"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name4"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name5"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name6"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name7"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name8"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name9"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name10"></telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn HeaderText="Image Name" UniqueName="ImageName" SortExpression="Name">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblName" Text='<%# Eval("Name") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadTextBox runat="server" ID="txbName" Text='<%# Eval("Name") %>'>
                                </telerik:RadTextBox>
                                <asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" ControlToValidate="txbName"
                                    ErrorMessage="Please, enter a name!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
                            </EditItemTemplate>
                            <HeaderStyle Width="30%"></HeaderStyle>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn HeaderText="Description" UniqueName="Description" DataField="Description">
                            <ItemTemplate>
                                <asp:Label ID="lblDescription" runat="server" Text='<%# TrimDescription(Eval("Description") as string) %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadTextBox ID="txbDescription" Width="300px" runat="server" TextMode="MultiLine"
                                    Text='<%# Eval("Description") %>' Height="150px">
                                </telerik:RadTextBox>
                            </EditItemTemplate>
                            <ItemStyle VerticalAlign="Top"></ItemStyle>
                        </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}") %>'></telerik:RadBinaryImage>
                            </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="36px"></HeaderStyle>
                        </telerik:GridButtonColumn>
                    </Columns>
                    <EditFormSettings>
                        <EditColumn ButtonType="ImageButton">
                        </EditColumn>
                    </EditFormSettings>
                    <PagerStyle AlwaysVisible="True"></PagerStyle>
                </MasterTableView>
                <ClientSettings>
                    <Scrolling AllowScroll="true" />
                </ClientSettings>
            </telerik:RadGrid>
        </div>
    </form>
</body>
</html>
