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
996 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
Comment Utility
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
Comment Utility
This is not even compiling.  It has the e.Command highlighted in the editor.
0
 
LVL 13

Expert Comment

by:SameerJagdale
Comment Utility
can you share the code? (not the snippet I mean)
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:iepaul
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you that was driving me nuts!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

9 Experts available now in Live!

Get 1:1 Help Now