<%@ Page Language="C#" MasterPageFile="~/Site.master" CodeFile="List.aspx.cs" Inherits="List" %>

<%@ Register src="~/DynamicData/Content/GridViewPager.ascx" tagname="GridViewPager" tagprefix="asp" %>
<%@ Register src="~/DynamicData/Content/FilterUserControl.ascx" tagname="DynamicFilter" tagprefix="asp" %>


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:DynamicDataManager ID="DynamicDataManager1" runat="server"
        EnableQueryStringSelection="true" AutoLoadForeignKeys="true" />

    <h2><%= table.DisplayName%></h2>

    <asp:ScriptManagerProxy runat="server" ID="ScriptManagerProxy1" />

    <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
        HeaderText="List of validation errors" />
    <asp:DynamicValidator runat="server" ID="GridViewValidator" ControlToValidate="GridView1" Display="None" />

    <br /><br />

    <asp:FilterRepeater ID="FilterRepeater" runat="server">
        <ItemTemplate>
            <asp:Label runat="server" Text='<%# Eval("DisplayName") %>' AssociatedControlID="DynamicFilter$DropDownList1" />
            <asp:DynamicFilter runat="server" ID="DynamicFilter" OnSelectedIndexChanged="OnFilterSelectedIndexChanged" />
        </ItemTemplate>
        <FooterTemplate><br /><br /></FooterTemplate>
    </asp:FilterRepeater>

    <asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource"
        AllowPaging="True" AllowSorting="True"
        CssClass="gridview" AlternatingRowStyle-CssClass="even">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:HyperLink ID="EditHyperLink" runat="server"
                        NavigateUrl='<%# table.GetActionPath(PageAction.Edit, GetDataItem()) %>'
                    Text="Edit" />&nbsp;<asp:LinkButton ID="DeleteLinkButton" runat="server" CommandName="Delete"
                        CausesValidation="false" Text="Delete"
                        OnClientClick='return confirm("Are you sure you want to delete this item?");'
                    />&nbsp;<asp:HyperLink ID="DetailsHyperLink" runat="server"
                        NavigateUrl='<%# table.GetActionPath(PageAction.Details, GetDataItem()) %>'
                        Text="Details" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>

        <PagerStyle CssClass="Footer"/>        
        <PagerTemplate>
            <asp:GridViewPager runat="server" />
        </PagerTemplate>
        <EmptyDataTemplate>
            There are currently no items in this table.
        </EmptyDataTemplate>
    </asp:GridView>

    <asp:LinqDataSource ID="GridDataSource" runat="server" EnableDelete="true">
        <WhereParameters>
            <asp:DynamicControlParameter ControlID="FilterRepeater" />
        </WhereParameters>
    </asp:LinqDataSource>

    <br />

    <asp:HyperLink ID="InsertHyperLink" runat="server">Insert new item</asp:HyperLink>
</asp:Content>
