<%@ page language="VB" %>

<script runat="server">

    Sub DetailsView1_ItemDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewDeletedEventArgs)
        GridView1.DataBind()
        GridView1.SelectedIndex = -1
    End Sub

    Sub DetailsView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs)
        GridView1.DataBind()
        GridView1.SelectedIndex = -1
    End Sub

    Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs)
        GridView1.DataBind()
    End Sub

    Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        
    End Sub

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
      
    End Sub

    Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        GridView1.SelectedIndex = -1
    End Sub
</script>

<html>
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="CustomerListSource" Runat="server" SelectCommand="SELECT CustomerID, CompanyName FROM Customers"
            ConnectionString="data source=W2000;Integrated Security=SSPI;Initial catalog=northwind">
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SingleCustomerSource" Runat="server" SelectCommand="SELECT CustomerID,CompanyName,ContactName,ContactTitle,Address,City,Country FROM Customers WHERE CustomerID=@CustomerID"
            ConnectionString="data source=W2000;Integrated Security=SSPI;Initial catalog=northwind" 
            DeleteCommand="DELETE Customers WHERE CustomerID=@original_CustomerID" 
            InsertCommand="INSERT INTO Customers (CustomerID,CompanyName,ContactName,ContactTitle,Address,City,Country)  VALUES (@CustomerID,@CompanyName,@ContactName,@ContactTile,@Address,@City,@Country)" 
            UpdateCommand="UPDATE Customers SET CompanyName=@CompanyName,ContactName=@ContactName,ContactTitle=@ContactTitle,Address=@Address,City=@City,Country=@Country WHERE CustomerID=@original_CustomerID">
            <DeleteParameters>
                <asp:Parameter Name="CustomerID" Type="String">
                </asp:Parameter>
            </DeleteParameters>
            <SelectParameters>
                <asp:ControlParameter Name="CustomerID" Type="String" ControlID="GridView1" PropertyName="SelectedValue" DefaultValue=" ">
                </asp:ControlParameter>
            </SelectParameters>
                          
            <UpdateParameters>
                <asp:Parameter Name="CompanyName" Type="String">
                </asp:Parameter>
                <asp:Parameter Name="ContactName" Type="String">
                </asp:Parameter>
                <asp:Parameter Name="ContactTitle" Type="String">
                </asp:Parameter>
                <asp:Parameter Name="Address" Type="String">
                </asp:Parameter>
                <asp:Parameter Name="City" Type="String">
                </asp:Parameter>
                <asp:Parameter Name="Country" Type="String">
                </asp:Parameter>
                <asp:Parameter Name="CustomerID" Type="String">
                </asp:Parameter>
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="CustomerID" Type="String">
                </asp:Parameter>
                <asp:Parameter Name="CompanyName" Type="String">
                </asp:Parameter>
                <asp:Parameter Name="ContactName" Type="String">
                </asp:Parameter>
                <asp:Parameter Name="ContactTile" Type="String">
                </asp:Parameter>
                <asp:Parameter Name="Address" Type="String">
                </asp:Parameter>
                <asp:Parameter Name="City" Type="String">
                </asp:Parameter>
                <asp:Parameter Name="Country" Type="String">
                </asp:Parameter>
            </InsertParameters>
        </asp:SqlDataSource>&nbsp;
        <asp:GridView ID="GridView1" Runat="server" DataSourceID="CustomerListSource" DataKeyNames="CustomerID"
            AutoGenerateColumns="False" BorderWidth="1px" BackColor="White" CellPadding="4"
            BorderColor="#CC9966" AllowPaging="True" AllowSorting="True" BorderStyle="None"
            PageSize="5" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnPageIndexChanged="GridView1_PageIndexChanged">
            <FooterStyle ForeColor="#330099" BackColor="#FFFFCC" Font-Names="Verdana" Font-Size="XX-Small" Font-Overline="True"></FooterStyle>
            <PagerStyle BackColor="#FFFFCC" HorizontalAlign="Center" ForeColor="#330099" Font-Italic="False" BorderStyle="None" Font-Overline="False" Font-Names="Verdana" Font-Size="XX-Small" Font-Underline="False" Wrap="True"></PagerStyle>
            <HeaderStyle ForeColor="#FFFFCC" Font-Bold="True" Font-Names="Verdana" Font-Size="XX-Small" BackColor="#FFFFC0"></HeaderStyle>
            <Columns>
                <asp:CommandField ShowSelectButton="True" CancelText="Anuluj" DeleteText="Usuń" EditText="Edytuj" InsertText="Wstaw" NewText="Nowy" SelectText="Zaznacz" UpdateText="Aktualizuj"></asp:CommandField>
                <asp:BoundField ReadOnly="True" HeaderText="CustomerID" DataField="CustomerID" SortExpression="CustomerID"></asp:BoundField>
                <asp:BoundField HeaderText="CompanyName" DataField="CompanyName" SortExpression="CompanyName"></asp:BoundField>
            </Columns>
            <SelectedRowStyle ForeColor="#663399" Font-Bold="True" BackColor="#FFCC66"></SelectedRowStyle>
            <RowStyle ForeColor="#330099" BackColor="White" Font-Overline="False" Font-Names="Verdana" Font-Size="XX-Small" Font-Strikeout="False"></RowStyle>
            <EmptyDataRowStyle Font-Size="XX-Small" />
        </asp:GridView>
    
    </div>
        <div>
            &nbsp;</div>
        <div>
            <asp:DetailsView ID="DetailsView1" Runat="server" Font-Size="XX-Small" Font-Names="Verdana"
                BorderStyle="None" BorderColor="#CC9966" CellPadding="4" BackColor="White" BorderWidth="1px"
                DataKeyNames="CustomerID" DataSourceID="SingleCustomerSource" AutoGenerateRows="False"
                Width="238px" OnItemDeleted="DetailsView1_ItemDeleted" OnItemInserted="DetailsView1_ItemInserted" OnItemUpdated="DetailsView1_ItemUpdated">
                <FooterStyle ForeColor="#330099" BackColor="#FFFFCC">
                </FooterStyle>
                <RowStyle ForeColor="#330099" BackColor="White">
                </RowStyle>
                <PagerStyle BackColor="#FFFFCC" HorizontalAlign="Center" ForeColor="#330099">
                </PagerStyle>
                <Fields>
                    <asp:BoundField ReadOnly="True" HeaderText="CustomerID" DataField="CustomerID" SortExpression="CustomerID">
                    </asp:BoundField>
                    <asp:BoundField HeaderText="CompanyName" DataField="CompanyName" SortExpression="CompanyName">
                    </asp:BoundField>
                    <asp:BoundField HeaderText="ContactName" DataField="ContactName" SortExpression="ContactName">
                    </asp:BoundField>
                    <asp:BoundField HeaderText="ContactTitle" DataField="ContactTitle" SortExpression="ContactTitle">
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Address" DataField="Address" SortExpression="Address">
                    </asp:BoundField>
                    <asp:BoundField HeaderText="City" DataField="City" SortExpression="City">
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Country" DataField="Country" SortExpression="Country">
                    </asp:BoundField>
                    <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" ShowInsertButton="True" CancelText="Anuluj" DeleteText="Usuń" EditText="Edytuj" InsertText="Wstaw" NewText="Nowy" SelectText="Zaznacz" UpdateText="Aktualizuj"></asp:CommandField>
                </Fields>
                <HeaderStyle ForeColor="#FFFFCC" Font-Bold="True" BackColor="#990000">
                </HeaderStyle>
                <EditRowStyle ForeColor="#663399" Font-Bold="True" BackColor="#FFCC66">
                </EditRowStyle>
            </asp:DetailsView>
            &nbsp;<br />
            &nbsp;
        </div>
        &nbsp;
    </form>
</body>
</html>
