Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
1,039 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

721 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