<%@ Page Language="VB" MasterPageFile="~/day02/MyMaster.master" Title="MultiViewコントロール" %>

<script runat="server">

    Protected Sub grid_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        mv.ActiveViewIndex = 1
    End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="cph" Runat="Server">
    <asp:MultiView ID="mv" runat="server" ActiveViewIndex="0">
        <asp:View ID="View1" runat="server">
            <br />
            <asp:GridView ID="grid" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="isbn" DataSourceID="GridSrc" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="grid_SelectedIndexChanged">
                <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <Columns>
                    <asp:BoundField DataField="title" HeaderText="書名" SortExpression="title" />
                    <asp:BoundField DataField="published" DataFormatString="{0:yyyy年MM月dd日}" HeaderText="発売日"
                        HtmlEncode="False" SortExpression="published" />
                    <asp:CommandField ButtonType="Button" ShowSelectButton="True" />
                </Columns>
                <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" />
            </asp:GridView>
            <asp:SqlDataSource ID="GridSrc" runat="server" CacheDuration="600" CacheExpirationPolicy="Sliding"
                ConnectionString="<%$ ConnectionStrings:MyDB %>" EnableCaching="True" SelectCommand="SELECT [isbn], [title], [published] FROM [Book] ORDER BY [published] DESC">
            </asp:SqlDataSource>
        </asp:View>
        <asp:View ID="View2" runat="server">
            <br />
            <asp:DetailsView ID="dv" runat="server" Height="50px" AutoGenerateRows="False" CellPadding="4" DataKeyNames="isbn" DataSourceID="DetailSrc" ForeColor="#333333" GridLines="None">
                <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <CommandRowStyle BackColor="#FFFFC0" Font-Bold="True" />
                <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                <Fields>
                    <asp:BoundField DataField="isbn" HeaderText="ISBNコード" ReadOnly="True" SortExpression="isbn" />
                    <asp:BoundField DataField="title" HeaderText="書名" SortExpression="title" />
                    <asp:BoundField DataField="price" DataFormatString="{0:#,###円}" HeaderText="価格" HtmlEncode="False"
                        SortExpression="price" />
                    <asp:BoundField DataField="published" DataFormatString="{0:yyyy年MM月dd日}" HeaderText="発売日"
                        HtmlEncode="False" SortExpression="published" />
                    <asp:CheckBoxField DataField="cdrom" HeaderText="CD-ROM" SortExpression="cdrom" />
                </Fields>
                <FieldHeaderStyle BackColor="#FFFF99" Font-Bold="True" />
                <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" />
            </asp:DetailsView>
            <asp:SqlDataSource ID="DetailSrc" runat="server" ConnectionString="<%$ ConnectionStrings:MyDB %>"
                DataSourceMode="DataReader" SelectCommand="SELECT [isbn], [title], [price], [published], [cdrom] FROM [Book] WHERE ([isbn] = @isbn)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="grid" Name="isbn" PropertyName="SelectedValue" Type="String" />
                </SelectParameters>
            </asp:SqlDataSource>
            &nbsp;
            <asp:LinkButton ID="lnkReturn" runat="server" CommandName="PrevView">一覧表へ</asp:LinkButton></asp:View>
    </asp:MultiView>
</asp:Content>

