Thank you..
Below is the code for the NewPhotoAlbum.aspx
<%@ Page Title="Create New Photo Album" Language="
VB" MasterPageFile="~/Masterpages/Frontend.master" AutoEventWireup="false" CodeFile="NewPhotoAlbum.aspx.
vb" Inherits="_NewPhotoAlbum" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:DetailsView ID="DetailsView1" Height="50px" Width="125px" AutoGenerateRows="False" DefaultMode="Insert" runat="server" InsertMethod="DetailsView1_InsertItem">
<Fields>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:CommandField ShowInsertButton="True" ShowCancelButton="False" />
</Fields>
</asp:DetailsView>
</asp:Content>
Code behind :
Partial Class _NewPhotoAlbum
Inherits BasePage
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
End Sub
Public Sub DetailsView1_InsertItem()
Dim photoAlbum As New PhotoAlbum()
TryUpdateModel(photoAlbum)
If ModelState.Isvalid Then
Using myEntities As New PlanetWroxEntities()
myEntities.PhotoAlbums.Add(photoAlbum)
myEntities.SaveChanges()
End Using
Response.Redirect(String.Format("ManagePhotoAlbum? PhotoAlbumId={0}", photoAlbum.Id.ToString()))
End If
End Sub
End Class
Below is the code for 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" DataKeyNames="Id" InsertItemPosition="LastItem" runat="server" SelectMethod="ListView1_GetData" InsertMethod="ListView1_InsertItem" DeleteMethod="ListView1_DeleteItem" >
<InsertItemTemplate>
<li>
Description: <asp:TextBox ID="Description" runat="server" TextMode="MultiLine" Text='<%# Bind("Description")%>' /><br />
ToolTip: <asp:TextBox ID="ToolTip" runat="server" Text='<%# Bind("ImageUrl")%>' /> <br />
<asp:Button ID="InsertButton" runat="server" Text="Insert" CommandName="Insert" />
</li>
</InsertItemTemplate>
<ItemTemplate>
<li>
Description: <asp:Label ID="Description" runat="server" Text='<%# Eval("Description")%>' /><br />
ToolTip: <asp:Label ID="ToolTip" runat="server" Text='<%# Eval("ToolTip")%>' /><br />
ImageUrl: <asp:Label ID="ImageUrl" runat="server" Text='<%# Eval("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>
Code behind:
Partial Class _ManagePhotoAlbum
Inherits BasePage
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
End Sub
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)
If ModelState.IsValid Then
Using myEntities As New PlanetWroxEntities()
picture.PhotoAlbumId = photoAlbumId
myEntities.Pictures.Add(picture)
myEntities.SaveChanges()
End Using
End If
End Sub
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