2015年12月21日 星期一

DataList包 DataList (DataList 的大腸包小腸)

ASP
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
  <ItemTemplate>
      <a><asp:Label ID="lb_title" runat="server" Text='<%# Eval("title") %>'></asp:Label></a>
      <asp:Label ID="lb_no" runat="server" Text='<%# Eval("no") %>'></asp:Label>
      <div>
          <asp:DataList ID="DataList2" runat="server">
            <ItemTemplate>
               <a><asp:Label ID="lb_title_s" runat="server" Text='<%# Eval("title") %>'></asp:Label></a>
            </ItemTemplate>
          </asp:DataList>
      </div>
  </ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:xxx.web.access %>" 
    ProviderName="<%$ ConnectionStrings:xxx.web.access.ProviderName %>" >
</asp:SqlDataSource>



.VB
Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
        Dim dl As DataList = Nothing
        Dim labTypeID As Label = Nothing

        dl = CType(e.Item.FindControl("DataList2"), DataList)
        labTypeID = CType(e.Item.FindControl("lb_no"), Label)

        Dim connString1 As String = WebConfigurationManager.ConnectionStrings("xxx.web.access").ConnectionString
        Dim conn As New OracleConnection(connString1)
        conn.Open()

        Dim Cmd1 As New OracleCommand
        Cmd1.Connection = conn
        Cmd1.CommandText = "select * from eip_web_item_content where id=4 and disable_date is null and content=" & labTypeID.Text & " order by ordernum"
        Dim dr1 As OracleDataReader = Cmd1.ExecuteReader
        Dim dt1 As New DataTable
        dt1.Load(dr1)
        dr1.Close()
        conn.Close()
        '<=DataList2的DataSource來源

        dl.DataSource = dt1
        dl.DataBind()
    End If

End Sub


畫面

沒有留言:

張貼留言