<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AutomaticOperationsDemo.aspx.cs" Inherits="Telerik.GridExamplesCSharp.DataEditing.AllEditableColumns.DefaultCS" %>
<%@ Register TagPrefix="radG" Namespace="Telerik.WebControls" Assembly="RadGrid.Net2" %>
<%@ Register TagPrefix="my" Namespace="MyGridNamespace" %>
<%@ Register TagPrefix="sds" Namespace="SessionDS" Assembly="SessionDataSource" %>

<!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">
		<style type="text/css">
        .MyImageButton
        {
           cursor: hand;
        }
        </style>			
		<!-- end of custom head section -->		
</head>
<body>
    <form id="mainForm" runat="server" style="width:600px" >    
        <my:MyGridExecutionTime ID="RadGrid1" runat="server" Skin="Inox" EnableAJAX="true" ShowStatusBar="true"
            AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" 
            AllowPaging="True" PageSize="10" AutoGenerateColumns="False" DataSourceID="SessionDataSource1"
            OnItemUpdated="RadGrid1_ItemUpdated" OnItemDeleted="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted">
            <PagerStyle Mode="NextPrevAndNumeric" />
            <MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataKeyNames="ProductID" DataSourceID="SessionDataSource1" HorizontalAlign="NotSet" AutoGenerateColumns="False">
                <Columns>
                    <radg:GridEditCommandColumn ButtonType="ImageButton" UpdateImageUrl="Img\Update.gif" 
                    EditImageUrl="Img\Edit.gif" InsertImageUrl="Img\Insert.gif" 
                    CancelImageUrl="Img\Cancel.gif" UniqueName="EditCommandColumn">
                        <HeaderStyle Width="20px" /> 
                        <ItemStyle CssClass="MyImageButton" />
                    </radg:GridEditCommandColumn>
                    <radG:GridBoundColumn DataField="ProductID" HeaderText="ID" ReadOnly="True"
                        SortExpression="ProductID" UniqueName="ProductID">
                        <HeaderStyle Width="20px" ForeColor="Silver" /> 
                        <ItemStyle ForeColor="Silver" />
                    </radG:GridBoundColumn>
                    <radG:GridBoundColumn DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName"
                        UniqueName="ProductName">
                    </radG:GridBoundColumn>
                    <radG:GridDropDownColumn DataField="CategoryID" DataSourceID="AccessDataSource2"
                        HeaderText="Category" ListTextField="CategoryName" ListValueField="CategoryID"
                        UniqueName="CategoryID">                        
                    </radG:GridDropDownColumn>
                    <radG:GridBoundColumn DataField="UnitsInStock" HeaderText="Units In Stock" SortExpression="UnitsInStock"
                        UniqueName="UnitsInStock">
                        <HeaderStyle Width="60px" />
                    </radG:GridBoundColumn>
                    <radG:GridBoundColumn DataField="QuantityPerUnit" HeaderText="Quantity Per Unit" SortExpression="QuantityPerUnit"
                        UniqueName="QuantityPerUnit" Visible="false" EditFormColumnIndex="1">
                    </radG:GridBoundColumn>
                    <radG:GridCheckBoxColumn DataField="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued"
                        UniqueName="Discontinued" EditFormColumnIndex="1">
                        <HeaderStyle Width="50px" />
                    </radG:GridCheckBoxColumn>
                    <radG:GridTemplateColumn HeaderText="UnitPrice" SortExpression="UnitPrice" UniqueName="TemplateColumn" EditFormColumnIndex="1">
                        <HeaderStyle Width="80px" />
                        <ItemTemplate>
                            <asp:Label runat="server" ID="lblUnitPrice" Text='<%# Eval("UnitPrice", "{0:C}") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox runat="server" ID="tbUnitPrice" Text='<%# Bind("UnitPrice") %>'></asp:TextBox><span style="color:Red">*</span><asp:RequiredFieldValidator ControlToValidate="tbUnitPrice" ErrorMessage="This field is required" runat="server" >
                            </asp:RequiredFieldValidator>
                        </EditItemTemplate>
                    </radG:GridTemplateColumn>
                    <radG:GridButtonColumn ConfirmText="Delete this product?" ButtonType="ImageButton" ImageUrl="Img\Delete.gif" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                        <HeaderStyle Width="20px" />
                        <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                    </radG:GridButtonColumn>
                </Columns>
                <EditFormSettings ColumnNumber="2" CaptionDataField="ProductName" CaptionFormatString="Edit properties of Product {0}">
                    <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                        <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
						<FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White" Width="100%" />
						<FormTableStyle CellSpacing="0" CellPadding="2" CssClass="module" Height="110px"
							BackColor="White" />
						<FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
						<EditColumn ButtonType="ImageButton" UpdateImageUrl="Img\Update.gif" EditImageUrl="Img\Edit.gif" InsertImageUrl="Img\Insert.gif" CancelImageUrl="Img\Cancel.gif" InsertText="Insert Order" UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit"></EditColumn>
						<FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
                </EditFormSettings>
            </MasterTableView>                      
        </my:MyGridExecutionTime><br />
      
        <sds:SessionDataSource ID="SessionDataSource1" runat="server" DataFile="~/App_Data/NWind.mdb"
            SelectCommand="SELECT ProductID, ProductName, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, Discontinued FROM [Products]" 
            DeleteCommand="DELETE FROM [Products] WHERE [ProductID] = ?" 
            InsertCommand="INSERT INTO Products(ProductName, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, Discontinued) VALUES (?, ?, ?, ?, ?, ?)" 
            UpdateCommand="UPDATE [Products] SET [ProductName] = ?, [CategoryID] = ?, [QuantityPerUnit] = ?, [UnitPrice] = ?, [UnitsInStock] = ?, [Discontinued] = ? WHERE [ProductID] = ? AND [ProductName] = ? AND [CategoryID] = ? AND [QuantityPerUnit] = ? AND [UnitPrice] = ? AND [UnitsInStock] = ? AND [Discontinued] = ?" 
            AutoincrementFields="ProductID" OldValuesParameterFormatString="original_{0}" ConflictDetection="CompareAllValues">
            <DeleteParameters>
                <asp:Parameter Name="original_ProductID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="ProductName" Type="String" />
                <asp:Parameter Name="QuantityPerUnit" Type="String" />
                <asp:Parameter Name="UnitPrice" Type="Decimal" />
                <asp:Parameter Name="UnitsInStock" Type="Int16" />
                <asp:Parameter Name="Discontinued" Type="Boolean" />
                <asp:Parameter Name="original_ProductID" Type="Int32" />
                <asp:Parameter Name="original_ProductName" Type="String" />
                <asp:Parameter Name="original_QuantityPerUnit" Type="String" />
                <asp:Parameter Name="original_UnitPrice" Type="Decimal" />
                <asp:Parameter Name="original_UnitsInStock" Type="Int16" />
                <asp:Parameter Name="original_Discontinued" Type="Boolean" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="ProductName" Type="String" />
                <asp:Parameter Name="QuantityPerUnit" Type="String" />
                <asp:Parameter Name="UnitPrice" Type="Decimal" />
                <asp:Parameter Name="UnitsInStock" Type="Int16" />
                <asp:Parameter Name="Discontinued" Type="Boolean" />
            </InsertParameters>
        </sds:SessionDataSource>
        &nbsp;<br />
        <br />
        <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/NWind.mdb"
            SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]"></asp:AccessDataSource>        
        <br />        
    </form>
</body>
</html>
