ItemInserted Event Help

M

Michael

I tried to duplicate the code at msdn to create an ItemInserted event
on my form. Can someone tell me why it's not working. The code is as
follows:


<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Sub FormView1_ItemInserted(ByVal sender As Object, ByVal e As
FormViewInsertedEventArgs)


'Sub EmployeeFormView_ItemInserted(ByVal sender As Object,
ByVal e As FormViewInsertedEventArgs)

' Use the Exception property to determine whether an exception
' occurred during the insert operation.
If e.Exception Is Nothing Then

' Use the AffectedRows property to determine whether the
' record was inserted. Sometimes an error might occur
that
' does not raise an exception, but prevents the insert
' operation from completing.
If e.AffectedRows = 1 Then

Response.Redirect("partsrequest.aspx")

Else

Response.Redirect("wolf.aspx")

' Use the KeepInInsertMode property to remain in
insert mode
' when an error occurs during the insert operation.
e.KeepInInsertMode = True

End If

Else

' Insert the code to handle the exception.
Response.Redirect("search.aspx")

' Use the ExceptionHandled property to indicate that the
' exception has already been handled.
e.ExceptionHandled = True
e.KeepInInsertMode = True

End If



End Sub



</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: left">
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"
DataSourceID="AccessDataSource1"
DefaultMode="Insert" Style="z-index: 16; left: 28px;
position: absolute; top: 210px" Width="240px">
<EditItemTemplate>
ID:
<asp:Label ID="IDLabel1" runat="server" Text='<%#
Eval("ID") %>'></asp:Label><br />
Scale1:
<asp:TextBox ID="Scale1TextBox" runat="server" Text='<
%# Bind("Scale1") %>'>
</asp:TextBox><br />
Scale2:
<asp:TextBox ID="Scale2TextBox" runat="server" Text='<
%# Bind("Scale2") %>'>
</asp:TextBox><br />
Employee:
<asp:TextBox ID="EmployeeTextBox" runat="server"
Text='<%# Bind("Employee") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
Scale1:
<asp:TextBox ID="Scale1TextBox" runat="server" Text='<
%# Bind("Scale1") %>'>
</asp:TextBox><br />
Scale2:
<asp:TextBox ID="Scale2TextBox" runat="server" Text='<
%# Bind("Scale2") %>'>
</asp:TextBox><br />
Employee:
<asp:TextBox ID="EmployeeTextBox" runat="server"
Text='<%# Bind("Employee") %>'></asp:TextBox><br />
<br />
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Record"></asp:LinkButton>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
&nbsp;<asp:LinkButton ID="InsertCancelButton"
runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
ID:
<asp:Label ID="IDLabel" runat="server" Text='<%#
Eval("ID") %>'></asp:Label><br />
Scale1:
<asp:Label ID="Scale1Label" runat="server" Text='<%#
Bind("Scale1") %>'></asp:Label><br />
Scale2:
<asp:Label ID="Scale2Label" runat="server" Text='<%#
Bind("Scale2") %>'></asp:Label><br />
Employee:
<asp:Label ID="EmployeeLabel" runat="server" Text='<%#
Bind("Employee") %>'></asp:Label><br />
<asp:LinkButton ID="EditButton" runat="server"
CausesValidation="False" CommandName="Edit"
Text="Edit">
</asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server"
CausesValidation="False" CommandName="Delete"
Text="Delete">
</asp:LinkButton>
<asp:LinkButton ID="NewButton" runat="server"
CausesValidation="False" CommandName="New"
Text="New">
</asp:LinkButton>
</ItemTemplate>
</asp:FormView>
<br />
<span style="font-size: 48pt">Scrap Data Entry&nbsp;</
span><asp:AccessDataSource ID="AccessDataSource1" runat="server"
ConflictDetection="CompareAllValues"
DataFile="~/App_Data/Spare_Parts_II_BCPC.mdb"
DeleteCommand="DELETE FROM [Scrap] WHERE [ID] = ? AND [Scale1] = ? AND
[Scale2] = ? AND [Employee] = ?"
InsertCommand="INSERT INTO [Scrap] ([Scale1], [Scale2],
[Employee]) VALUES (?, ?, ?)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [Scrap]"
UpdateCommand="UPDATE [Scrap] SET [Scale1] = ?, [Scale2]
= ?, [Employee] = ? WHERE [ID] = ? AND [Scale1] = ? AND [Scale2] = ?
AND [Employee] = ?">
<DeleteParameters>
<asp:parameter Name="original_ID" Type="Int32" />
<asp:parameter Name="original_Scale1" Type="Single" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Scale1" Type="Single" />
<asp:parameter Name="Scale2" Type="Single" />
<asp:parameter Name="Employee" Type="String" />
<asp:parameter Name="original_ID" Type="Int32" />
<asp:parameter Name="original_Scale1" Type="Single" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="Scale1" Type="Single" />
<asp:parameter Name="Scale2" Type="Single" />
<asp:parameter Name="Employee" Type="String" />
</InsertParameters>
</asp:AccessDataSource>

</div>
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top