Hi Imar,
I have the following error:
Quote:
Object reference not set to an instance of an object.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object
Line 9: myPicture.PhotoAlbumId = PhotoAlbumId
|
The code in the file ManagePhotoAlbum.aspx is as follows
Code:
<%@ Page Title="Manage Photo Album" Language="VB" Debug="true" MasterPageFile="~/MasterPages/ProdSupervisor.master" AutoEventWireup="false" CodeFile="ManagePhotoAlbum.aspx.vb" Inherits="SPV_Product_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="ProductId"
DataSourceID="EntityDataSource1" InsertItemPosition="LastItem">
<InsertItemTemplate>
<li style="">
<br />ProductName:
<asp:TextBox ID="ProductNameTextBox" runat="server"
Text='<%# Bind("ProductName") %>' />
<br />CategoryId:
<asp:TextBox ID="CategoryIdTextBox" runat="server"
Text='<%# Bind("CategoryId") %>' />
<br />Brand:
<asp:TextBox ID="BrandTextBox" runat="server" Text='<%# Bind("Brand") %>' />
<br />Model:
<asp:TextBox ID="ModelTextBox" runat="server" Text='<%# Bind("Model") %>' />
<br />Size:
<asp:TextBox ID="SizeTextBox" runat="server" Text='<%# Bind("Size") %>' />
<br />Price:
<asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>' />
<br />Tooltip:
<asp:TextBox ID="TooltipTextBox" runat="server" Text='<%# Bind("Tooltip") %>' />
<br />ImageUrl:
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />SystemInputDate:
<br />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
</li>
</InsertItemTemplate>
<ItemTemplate>
<li style="">
<br />
ProductName:
<asp:Label ID="ProductNameLabel" runat="server"
Text='<%# Eval("ProductName") %>' />
<br />
CategoryId:
<asp:Label ID="CategoryIdLabel" runat="server"
Text='<%# Eval("CategoryId") %>' />
<br />
Brand:
<asp:Label ID="BrandLabel" runat="server" Text='<%# Eval("Brand") %>' />
<br />
Model:
<asp:Label ID="ModelLabel" runat="server" Text='<%# Eval("Model") %>' />
<br />
Size:
<asp:Label ID="SizeLabel" runat="server" Text='<%# Eval("Size") %>' />
<br />
Price:
<asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price") %>' />
<br />
Tooltip:
<asp:Label ID="TooltipLabel" runat="server" Text='<%# Eval("Tooltip") %>' />
<br />
<%-- <asp:Label ID="ImageUrlLabel" runat="server" TextBox='<%# Eval("ImageUrl") %>' />
--%>
<asp:Image ID="ImageUrl" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' />
<br />
SystemInputDate:
<asp:Label ID="SystemInputDateLabel" runat="server"
Text='<%# Eval("SystemInputDate") %>' />
<br />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
</li>
</ItemTemplate>
<LayoutTemplate>
<ul class="ItemContainer">
<li runat="server" id="itemPlaceholder" />
</ul>
<div style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowNextPageButton="False" ShowPreviousPageButton="False" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True"
ShowNextPageButton="False" ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
</asp:ListView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=ProductsEntities3"
DefaultContainerName="ProductsEntities3"
EnableFlattening="False" EntitySetName="Products"
Where="it.PhotoAlbum.Id=@PhotoAlbumId" EnableDelete="True"
EnableInsert="True">
<WhereParameters>
<asp:QueryStringParameter Name="PhotoAlbumId" QueryStringField="PhotoAlbumId"
Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>
</asp:Content>
the code in
vb file is as follows
Code:
Imports ProductsModel
Partial Class SPV_Product_ManagePhotoAlbum
Inherits System.Web.UI.Page
Protected Sub EntityDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.EntityDataSourceChangingEventArgs) Handles EntityDataSource1.Inserting
Dim PhotoAlbumId As Integer = Convert.ToInt32(Request.QueryString.Get("PhotoAlbumId"))
Dim myPicture As Product = CType(e.Entity, Product)
myPicture.PhotoAlbumId = PhotoAlbumId
'******************************************************
'For saving file to disk page 516
'updates the imageurl property of the picture instance
' BEGIN
'******************************************************
Dim FileUpload1 As FileUpload = CType(ListView1.InsertItem.FindControl("FileUpload1"), FileUpload)
Dim virtualFolder As String = "~/images/Products/"
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(physicalFolder, fileName & extension))
myPicture.ImageUrl = virtualFolder & fileName & extension
'******************************************************
' page 516
' END
'******************************************************
End Sub
Protected Sub ListView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewInsertEventArgs) Handles ListView1.ItemInserting
'Dim FileUpload1 As FileUpload = CType(ListView1.InsertItem.FindControl("FileUpload1"), FileUpload)
'If Not FileUpload1.HasFile OrElse
'Not FileUpload1.FileName.ToLower().EndsWith(".jpg") Then
' Dim cusValImage As CustomValidator =
' CType(ListView1.InsertItem.FindControl("cusValImage"), CustomValidator)
' cusValImage.IsValid = False
' e.Cancel = True
'End If
End Sub
End Class
Table name Product field list is as follows:
Quote:
table name : Product
fields name: ProductId, ProductName, CategoryId, Brand, Model, Size, Price, Tooltip, ImageUrl, PhotoAlbumId, SystemInputDate
|
SystemInputDate field in the table has a Default Value or Binding property set to as follows
Please Help
Thank you
Oruc