Solved

In my ItemInserted event for the formview control, how do I get the key value of the newly inserted row?

Posted on 2008-10-31
6
1,006 Views
Last Modified: 2012-08-13
Hello, I have a formview control with DefaultMode="Insert".  In my ItemInserted event, how do I get the key value of the newly inserted row?

I have seen this answer in experts exchange http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_22917638.html?sfQueryTermInfo=1+ident+iteminsert but it is for C#

I converted to VB.NET and got this -
        If True Then
            If e.Exception Is Nothing Then
                Label1.Text = [String].Format("Department '{0}' successfully added.", e.Command.Parameters("@DepartmentID").Value)
            Else
                Label1.Text = "Unable to add department."
                e.ExceptionHandled = True
            End If
        End If

This is giving an error -

'Command' is not a member of 'System.Web.UI.WebControls.DetailsViewInsertedEventArgs'.

0
Comment
Question by:iepaul
  • 3
  • 3
6 Comments
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22849631
it looks ok to me.. apart from this:
[String].Format
should be:

String.Format
Can you put the stack trace of the error?
0
 

Author Comment

by:iepaul
ID: 22849693
This is not even compiling.  It has the e.Command highlighted in the editor.
0
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22849728
can you share the code? (not the snippet I mean)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:iepaul
ID: 22849831
Detailsview Insert statement
InsertCommand="INSERT INTO [tblSAPrepProjects] ([fldReg], [fldSerial], [fldProj], [fldCustomer], [fldStart], [fldLastChange]) VALUES (@fldReg, @fldSerial, @fldProj, @fldCustomer, @fldStart, @fldLastChange); SELECT @ProjectID = @@IDENTITY"

        <InsertParameters>
            <asp:Parameter Name="fldReg" Type="String" />
            <asp:Parameter Name="fldSerial" Type="String" />
            <asp:Parameter Name="fldProj" Type="String" />
            <asp:Parameter Name="fldCustomer" Type="String" />
            <asp:Parameter Name="fldStart" Type="DateTime" />
            <asp:Parameter Name="fldLastChange" Type="String" />
            <asp:parameter direction="Output" name="ProjectID" type="Int32" />
        </InsertParameters>

VB Code
Protected Sub DetailsView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles DetailsView1.ItemInserted
        If True Then
            If e.Exception Is Nothing Then
                Label1.Text = String.Format("Department '{0}' successfully added.", e.Command.Parameters("@ProjectID").Value)
                Else
                Label1.Text = "Unable to add department."
                e.ExceptionHandled = True
            End If
        End If
       
    End Sub
0
 
LVL 13

Accepted Solution

by:
SameerJagdale earned 500 total points
ID: 22849881
there you go.. you are handling detailsview_iteminserted event.. and the C# code is for sqldatasource_inserted event:
 

 Protected Sub SqlDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Inserted

        If (e.Exception Is Nothing) Then

            lblMessage.Text = String.Format("Department '{0}' successfully added.", e.Command.Parameters("@DepartmentID").Value)

        Else

            lblMessage.Text = "Unable to add department."

            e.ExceptionHandled = True

        End If
 

        
 

    End Sub

Open in new window

0
 

Author Closing Comment

by:iepaul
ID: 31512007
Thank you that was driving me nuts!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Please explain "Multi-Tenant Services" 5 63
Help with solving error related to resources file 4 36
c# string handling 1 27
Windows Media Player 2 14
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now