Here's the full aspx file:
HTML Code:
<%@ Page Title="Create Photo Album" Language="C#" MasterPageFile="~/MasterPages/Thread.master" AutoEventWireup="true" CodeFile="NewPhotoAlbum.aspx.cs" Inherits="Demos_NewPhotoAlbum" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Thread" Runat="Server">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ID" DataSourceID="EntityDataSource1" DefaultMode="Insert" Height="50px" Width="125px">
<Fields>
<%--<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" InsertVisible="false"/>--%>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:CommandField ShowInsertButton="true" />
</Fields>
</asp:DetailsView>
<asp:EntityDataSource ID="EntityDataSource1" EnableInsert="true" runat="server" ConnectionString="name=AnimeCoffeeEntities" DefaultContainerName="AnimeCoffeeEntities" EnableFlattening="False" EntitySetName="PhotoAlbumTables" OnInserted="EntityDataSource1_Inserted">
</asp:EntityDataSource>
</asp:Content>
Here's the codebehind:
HTML Code:
using AnimeCoffeeModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Demos_NewPhotoAlbum : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void EntityDataSource1_Inserted(object sender, EntityDataSourceChangedEventArgs e)
{
if (e.Entity != null)
{
PhotoAlbumTable myPhotoAlbum = (PhotoAlbumTable)e.Entity;
Response.Redirect(string.Format("~/Demos/ManagePhotoAlbum.aspx?PhotoAlbumID={3}", myPhotoAlbum.ID.ToString()));
}
}
}
Here's the browser link on error:
http://localhost:49261/Demos/NewPhotoAlbum.aspx
also here's the full error:
Cannot insert explicit value for identity column in table 'PhotoAlbumTable' when IDENTITY_INSERT is set to OFF.
AnimeCoffee is the name of my mdf file by the way and my masterpage is nested from SuperPage.master(for header,nav, footer) to a masterpage for specific webforms, with this one it is Thread.master So it's like SuperPage.master->Thread.master