Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1049
  • Last Modified:

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

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
iepaul
Asked:
iepaul
  • 3
  • 3
1 Solution
 
SameerJagdaleCommented:
it looks ok to me.. apart from this:
[String].Format
should be:

String.Format
Can you put the stack trace of the error?
0
 
iepaulAuthor Commented:
This is not even compiling.  It has the e.Command highlighted in the editor.
0
 
SameerJagdaleCommented:
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.

 
iepaulAuthor Commented:
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
 
SameerJagdaleCommented:
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
 
iepaulAuthor Commented:
Thank you that was driving me nuts!
0

Featured Post

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!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now