<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" InsertText="Insert" UpdateText="Update" DeleteText="Delete" ButtonType="Link" />
OnItemCommand="DetailsViewCommandEventHandler"
OnItemInserting="dvRecipeItem_ItemInserting"
OnItemInserted="dvRecipeItem_ItemInserted"
code behind: Public Event ItemCommand As DetailsViewCommandEventHandler
Private Sub dvRecipeItem_ItemInserted(sender As Object, e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles dvRecipeItem.ItemInserted
End Sub
Private Sub dvRecipeItem_ItemInserting(sender As Object, e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles dvRecipeItem.ItemInserting
End Sub
OnItemCommand="dvRecipeItem_CommandEventHandler"
OnItemInserting="dvRecipeItem_ItemInserting"
OnItemInserted="dvRecipeItem_ItemInserted">
Private Sub dvRecipeItem_CommandEventHandler(source As Object, e As DetailsViewCommandEventHandler)
End Sub
Private Sub dvRecipeItem_ItemInserted(sender As Object, e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles dvRecipeItem.ItemInserted
End Sub
Private Sub dvRecipeItem_ItemInserting(sender As Object, e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles dvRecipeItem.ItemInserting
End Sub
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" DataKeyNames="DocumentID" DataSourceID="SqlDataSource1" OnPageIndexChanged="DetailsView1_PageIndexChanged" DataMember="DefaultView">
DataKeyNames="Id"
<asp:BoundField DataField="ItemNumber" HeaderText="Item Number" SortExpression="ItemNumber" ApplyFormatInEditMode="True" />
<asp:BoundField DataField="ModifiedBy" HeaderText="Modified By" SortExpression="ModifiedBy" ApplyFormatInEditMode="True" />
Do I have to add more DataKeyNames?DataKeyNames="Id"
DataKeyNames="ItemNumber"
DataKeyNames="ModifiedBy"
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" ApplyFormatInEditMode="True" />
<asp:BoundField DataField="ItemNumber" HeaderText="Item Number" SortExpression="ItemNumber" ApplyFormatInEditMode="True" />
<asp:BoundField DataField="VersionNumber" HeaderText="VersionNumber" SortExpression="VersionNumber" ApplyFormatInEditMode="True" />
<asp:BoundField DataField="ModifiedDateTime" HeaderText="Modified Date Time" SortExpression="ModifiedDateTime" ApplyFormatInEditMode="True" />
<asp:BoundField DataField="ModifiedBy" HeaderText="Modified By" SortExpression="ModifiedBy" ApplyFormatInEditMode="True" />
Protected Sub dvRecipeItem_ItemCommandEventHandler(sender As [Object], e As DetailsViewCommandEventArgs)
If e.CommandName = "Insert" Then
If Not IsNothing(Me.dvRecipeItem.Rows(1).Cells(1).Text.ToString()) Then
' Log Insert
Dim strItemNumber As String = Me.dvRecipeItem.Rows(1).Cells(1).Text.ToString()
Dim strModifiedBy As String = Me.dvRecipeItem.Rows(4).Cells(1).Text.ToString()
Dim myAppLog As New AppLogClass(inEventCode:="Recipe-Insert", inItemCode:=strItemNumber, inDetailCode:=Membership.GetUser.UserName, inDescription:="Item Inserted By: " & strModifiedBy, inNote:=strModifiedBy)
myAppLog.Save()
End If
End If
End Sub
If e.CommandName = "Update" Then
If Not IsNothing(Me.dvRecipeItem.DataKey(1).ToString()) Then
' Log Update
Dim strItemNumber As String = Me.dvRecipeItem.DataKey(1).ToString()
Dim strModifiedBy As String = Me.dvRecipeItem.DataKey(2).ToString()
Dim myAppLog As New AppLogClass(inEventCode:="Recipe-Update", inItemCode:=strItemNumber, inDetailCode:=Membership.GetUser.UserName, inDescription:="Item Updated By: " & strModifiedBy, inNote:=strModifiedBy)
myAppLog.Save()
End If
End If
If e.CommandName = "Insert" Then
If Not IsNothing(Me.dvRecipeItem.Rows(1).Cells(1).Text.ToString()) Then
' Log Insert
Dim strItemNumber As String = Me.dvRecipeItem.Rows(1).Cells(1).Text.ToString()
Dim strModifiedBy As String = Me.dvRecipeItem.Rows(4).Cells(1).Text.ToString()
Dim myAppLog As New AppLogClass(inEventCode:="Recipe-Insert", inItemCode:=strItemNumber, inDetailCode:=Membership.GetUser.UserName, inDescription:="Item Inserted By: " & strModifiedBy, inNote:=strModifiedBy)
myAppLog.Save()
End If
End If
Dim myContext As New OLTPEntities
Dim myRecipeRecord = myContext.RefineRecipe.Where("it.Id=" & Me.dvRecipeItem.DataKey(1).ToString()).First
'Update (log 1 row in AppLog with list of new field values in Notes field, Example: “ID=1, ItemNumber=12204, etc.”)
If e.CommandName = "Update" Then
If Not IsNothing(Me.dvRecipeItem.DataKey(1).ToString()) Then
' Log Update
Dim strItemNumber As String = Me.dvRecipeItem.DataKey(1).ToString()
Dim strModifiedBy As String = Me.dvRecipeItem.DataKey(2).ToString()
Dim myAppLog As New AppLogClass(inEventCode:="Recipe-Update", inItemCode:=strItemNumber, inDetailCode:=Membership.GetUser.UserName, inDescription:="Item Updated By: " & strModifiedBy, inNote:=myRecipeRecord.ToString())
myAppLog.Save()
End If
End If
Dim myRecipeRecord = myContext.RefineRecipe.Where("it.Id=" & Me.dvRecipeItem.DataKey(1).ToString()).First
Dim myRecipeRecord = myContext.RefineRecipe.Where("it.Id=" & Me.dvRecipeItem.DataKey(0).ToString())
Open in new window
and then on the code behind:
Open in new window
but i get an error:
BC30456: 'dvRecipeItem_ItemInserted