문제

I have this form on VS2012 with asp.net. First I do search for the patron, then go to verify information for that patron. This patron information is displayed in ItemTemplate(ReadOnly). If that is not the patron they are looking for then they can add a new patron with "New button" (asp.net code). I am able to get the id of the new Patron(which is PK). However I am not able to display this newly created record on the form after inserting. It still displays the record which was on display. Since this a formview I did not enable "Paging".

Is it possible to call the pageload event from datasource_inserted event? Then I can pass the new patron ID for display. I declared this ID as global variable?

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim lvPatronID As String
    lvPatronID = Request.QueryString("value1")
    If lvPatronID = "" Then
        frmPatronView.ChangeMode(FormViewMode.Insert)
    Else
        frmPatronView.ChangeMode(FormViewMode.ReadOnly)
        GvPatronID = lvPatronID
        lblPatronID.Text = GvPatronID
    End If 


Protected Sub PatronDS_Inserted(sender As Object, e As SqlDataSourceStatusEventArgs) Handles PatronDS.Inserted
    NewID = e.Command.Parameters("@PatronID").Value.ToString
    GvPatronID = NewID
End Sub
도움이 되었습니까?

해결책

Well I answered part of my own question. The following change to the Inserted event will let me view the newly inserted data. I have another button to add new record in the emptytemplate of the search form. This is why I am changing the mode to insert as the default mode is readonly. This will let me insert the data but after inserting it doesn't display the form at all. Not sure why Inserted event is not kicking in properly.

    Protected Sub PatronDS_Inserted(sender As Object, e As SqlDataSourceStatusEventArgs) Handles PatronDS.Inserted
    Dim NewID As String = Nothing
    Try
        NewID = e.Command.Parameters("@PatronID").Value.ToString
        PatronDS.SelectCommand = "SELECT * FROM tblPatron WHERE PatronID='" & NewID & "'"
        lblPatronID.Text = NewID.Trim()
        frmPatronView.DataBind()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top