Here's the code I have for that. It all appears to be the same code provided from the source code, Thanks
Managephotoalbum.aspx
<%@ Page Title="Manage Photo Album" Language="
VB" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="false" CodeFile="ManagePhotoAlbum.aspx.
vb" Inherits="_ManagePhotoAlbum" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="Server">
<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id" InsertItemPosition="LastItem" SelectMethod="ListView1_GetData" InsertMethod="ListView1_InsertItem" DeleteMethod="ListView1_DeleteItem" ItemType="Picture">
<InsertItemTemplate>
<li>Description:
<asp:RequiredFieldValidator ID="reqDesc" ControlToValidate="Description" runat="server" ErrorMessage="Enter a description." />
<asp:TextBox ID="Description" runat="server" TextMode="MultiLine" Text='<%# BindItem.Description %>' /><br />
ToolTip:
<asp:RequiredFieldValidator ID="reqToolTip" ControlToValidate="ToolTip" runat="server" ErrorMessage="Enter a tool tip." />
<asp:TextBox ID="ToolTip" runat="server" Text='<%# BindItem.ToolTip %>' /><br />
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<asp:CustomValidator ID="cusValImage" runat="server" ErrorMessage="Select a valid .jpg file." />
<asp:Button ID="InsertButton" runat="server" Text="Insert" CommandName="Insert" />
</li>
</InsertItemTemplate>
<ItemTemplate>
<li>Description:
<asp:Label ID="Description" runat="server" Text='<%# Item.Description %>' /><br />
ToolTip:
<asp:Label ID="ToolTip" runat="server" Text='<%# Item.ToolTip %>' /><br />
<asp:Image ID="ImageUrl" runat="server" ImageUrl='<%# Item.ImageUrl %>' /><br />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" CausesValidation="False" />
</li>
</ItemTemplate>
<LayoutTemplate>
<ul class="ItemContainer">
<li runat="server" id="itemPlaceholder" />
</ul>
</LayoutTemplate>
</asp:ListView>
</asp:Content>
managephotalbum.aspx.
vb
Imports System.Web.ModelBinding
Partial Class _ManagePhotoAlbum
Inherits BasePage
' The return type can be changed to IEnumerable, however to support
' paging and sorting, the following parameters must be added:
' ByVal maximumRows as Integer
' ByVal startRowIndex as Integer
' ByRef totalRowCount as Integer
' ByVal sortByExpression as String
Public Function ListView1_GetData(<QueryString("PhotoAlbumId")> PhotoAlbumId As Integer) As IQueryable
Dim myEntities As New PlanetWroxEntities()
Return From p In myEntities.Pictures
Where p.PhotoAlbumId = PhotoAlbumId
Select p
End Function
Public Sub ListView1_InsertItem(<QueryString("PhotoAlbumId")> photoAlbumId As Integer)
Dim picture As New Picture()
TryUpdateModel(picture)
Dim FileUpload1 As FileUpload = CType(ListView1.InsertItem.FindControl("FileUpload 1"), FileUpload)
If Not FileUpload1.HasFile OrElse Not FileUpload1.FileName.ToLower().EndsWith(".jpg") Then
Dim cusValImage As CustomValidator = CType(ListView1.InsertItem.FindControl("cusValImag e"), CustomValidator)
cusValImage.IsValid = False
ModelState.AddModelError("Invalid", cusValImage.ErrorMessage)
End If
If ModelState.IsValid AndAlso Page.IsValid Then
Using myEntities As New PlanetWroxEntities()
picture.PhotoAlbumId = photoAlbumId
Dim virtualFolder As String = "~/GigPics/"
Dim physicalFolder As String = Server.MapPath(virtualFolder)
Dim fileName As String = Guid.NewGuid().ToString()
Dim extension As String = System.IO.Path.GetExtension(FileUpload1.FileName)
FileUpload1.SaveAs(System.IO.Path.Combine(physical Folder, fileName + extension))
picture.ImageUrl = virtualFolder + fileName + extension
myEntities.Pictures.Add(picture)
myEntities.SaveChanges()
End Using
End If
End Sub
' The id parameter name should match the DataKeyNames value set on the control
Public Sub ListView1_DeleteItem(ByVal id As Integer)
Using myEntities As New PlanetWroxEntities()
Dim picture = (From p In myEntities.Pictures
Where p.Id = id
Select p).Single()
myEntities.Pictures.Remove(picture)
myEntities.SaveChanges()
End Using
End Sub
End Class