<%@ Page Language="VB" AutoEventWireup="false" CodeFile="EmpSales.aspx.vb" Inherits="EmpSales" %>
<!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 id="Head1" runat="server">
<title>Untitled Page</title>
<style type="text/css">
div{width:300px;}
.title{
background-color:Maroon;
color:White;
}
.alternate
{
background-color:Silver;
}
.item
{
}
</style>
</head>
<body>
<form id="form2" runat="server">
<asp:DataList id="DataList1" runat="server" onItemDataBound="ItemDB"
Width="328px">
<ItemTemplate>
<div style="background-color:Silver"><asp:Label Runat="server" text=<%#DataBinder.Eval(Container.DataITem, "Title")%> ID="lblTitle" /></div>
<div style="background-color:White"><asp:Label Runat="server" text=<%#DataBinder.Eval(Container.DataITem, "FirstName")%> ID="Label1" /> <asp:Label Runat="server" text=<%#DataBinder.Eval(Container.DataITem, "LastName")%> ID="lblLastName" /></div>
</ItemTemplate>
</asp:DataList>
<br />
<br />
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="LVItemDB" >
<ItemTemplate>
<span>
<div class="title"><asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' /></div>
<div class="item"><asp:Label ID="LastNameLabel" runat="server" Text='<%# Eval("LastName") %>' />, <asp:Label ID="FirstNameLabel" runat="server" Text='<%# Eval("FirstName") %>' /></div>
</span>
</ItemTemplate>
<LayoutTemplate>
<div ID="itemPlaceholderContainer" runat="server"
style="font-family: Verdana, Arial, Helvetica, sans-serif;">
<span ID="itemPlaceholder" runat="server" />
</div>
</LayoutTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT LastName, FirstName, Title FROM Employees WHERE (Title <> '') order by Title">
</asp:SqlDataSource>
</form>
</body>
</html>
Imports System.Data
Imports System.Data.SqlClient
Partial Class EmpSales
Inherits System.Web.UI.Page
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindTitle()
End If
End Sub
'Bind Data to DataList Populating the Dataset
Sub BindTitle()
Dim ds As New DataSet
Dim sqlStmt As String = "SELECT * FROM Employees where title <> '' order by title"
Dim conString As String = "server=localhost;database=Northwind;integrated security=sspi;"
Dim da As SqlDataAdapter = New SqlDataAdapter(sqlStmt, conString)
da.Fill(ds, "Table")
DataList1.DataSource = ds
DataList1.DataBind()
End Sub
'The DataView ItemDataBound Event
Protected Sub ItemDB(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
Dim strval As String = CType(e.Item.FindControl("lblTitle"), Label).Text
Dim title As String = ViewState("title")
If title = strval Then
CType(e.Item.FindControl("lblTitle"), Label).Text = ""
e.Item.Visible = False
Else
title = strval
ViewState("title") = title
CType(e.Item.FindControl("lblTitle"), Label).Text = title
e.Item.Visible = True
End If
End If
End Sub
'The ListView ItemDataBound Event
Protected Sub LVItemDB(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs)
' List view doesn't need a different
If e.Item.ItemType = ListViewItemType.DataItem Then
Dim strval As String = CType(e.Item.FindControl("TitleLabel"), Label).Text
Dim title As String = ViewState("lvtitle")
If title = strval Then
CType(e.Item.FindControl("TitleLabel"), Label).Text = ""
Else
title = strval
ViewState("lvtitle") = title
CType(e.Item.FindControl("TitleLabel"), Label).Text = title
End If
End If
End Sub
End Class