ASP.Netのお勉強

DataList@ASP.Net

DataListコントロールです。
Container.DataItemに設定して、データを表示します。

以下では、Stringの配列をDataSourceに設定し、DataBindを行い表示しています。

●aspx

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="SampleDataList.aspx.vb" Inherits="SampleDataList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>DataList</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" /><br />
        <br />
        <asp:DataList ID="DataList1" runat="server">
            <HeaderTemplate>
                項目
            </HeaderTemplate>
            <ItemTemplate>
                <%# Container.DataItem %>
            </ItemTemplate>
            <ItemStyle BackColor="White" BorderColor="Black"
                BorderStyle="Solid" BorderWidth="1px" />
            <HeaderStyle BackColor="#C0FFFF" BorderColor="Teal"
            BorderStyle="Solid" BorderWidth="1px" />
        </asp:DataList>
    </div>
</form>
</body>
</html>


●vb

Partial Class SampleDataList
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strDS As String() = {"item1", "item2", "item3", "item4",
"item5", "item6","item7", "item8", "item9", "item10",
"item11", "item12"}

        DataList1.DataSource = strDS
        DataList1.DataBind()

    End Sub
End Class



Copyright (C) ASP.Netのお勉強. All Rights Reserved.