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,027 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to make search between pages 17 60
make control visible based off other control value 7 45
ASP.NET Complete Life Cycle for all the controls 2 46
vb.net code 9 29
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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

710 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