0

私は投稿や記事を読んでいて、少し混乱しており、その結果、現時点では時間がありません。

誰かが私のコードを見て、どこが間違っているか教えてもらえますか?

    Partial Class PayerContacts
    Inherits System.Web.UI.Page

    Dim connStrDRContacts As String = ConfigurationManager.ConnectionStrings("DRContacts_SQL").ConnectionString

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        navBuild()
    End Sub

    Protected Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init

        If IsPostBack Then
            LoadContacts(ViewState("objSender"))
        End If

    End Sub

    Private Function navBuild() As Integer

        Dim SQLstrDRs As String = "SELECT * FROM DRList"
        Dim DbConnDRs As SqlConnection = New SqlConnection(connStrDRContacts)
        DbConnDRs.Open()
        Dim dtDRsTemp As New DataTable
        Dim SQLAdapterDRs As New SqlDataAdapter(SQLstrDRs, DbConnDRs)
        SQLAdapterDRs.Fill(dtDRsTemp)

        'Loop through each row of the DataView to create HTML table data

        Dim NewTableRow As New TableRow

        For Each row As DataRow In dtDRsTemp.Rows

    'CREATE table with button to display contacts related to client (one to many)   
            Dim NewTableButton As LinkButton = New LinkButton
            NewTableButton.ID = "btnDRName" & NewTableText
            NewTableButton.ViewStateMode = UI.ViewStateMode.Enabled
            AddHandler NewTableButton.Click, AddressOf LoadContacts

        Next

        Return 0

    End Function

    Protected Sub LoadContacts(sender As Object, e As EventArgs)

        Dim LoopCount As Integer = 0

        Dim SQLstrLoadTable As String = "SELECT * FROM ContactList WHERE DRVendor = '" & sender.Text.ToString & "'"
    and so on....
        SQLAdapterLoadTable.Fill(dtLoadTableTemp)

        Dim NewTableRow As New TableRow

        For Each row As DataRow In dtLoadTableTemp.Rows

            'CREATE Accordion to display data
            NewAccordion.ID = "ContactAccordion" & LoopCount
            NewAccordion.Visible = True
    blah, blah...

            'SET Pane
            NewAccordionPane.HeaderContainer.ID = "PaneHeader" & LoopCount
            NewAccordionPane.ContentContainer.ID = "PaneContent" & LoopCount

    'CREATE button to open ModalPopup to EDIT each record
            Dim imgGear As New ImageButton
            imgGear.ID = "btnGear" & row!ID.ToString
            imgGear.ViewStateMode = UI.ViewStateMode.Enabled
            AddHandler imgGear.Click, AddressOf EditRecord

            'LOAD Pane
            NewAccordionPane.HeaderContainer.Controls.Add(NewHeaderTable)
            NewAccordionPane.ContentContainer.Controls.Add(New LiteralControl(NewTableText))


        ViewState("objSender") = sender

    End Sub

    Protected Sub EditRecord(ByVal sender As Object, ByVal e As EventArgs)
        'Open ModalPopup to edit record
        popup.Show()
        pnlAddEdit.Visible = True

    End Sub

End Class
4

1 に答える 1

0

ViewState と動的コントロールに関する Infinities Loop の記事は、すべての Webforms 開発者が実際に読む必要があります。

http://mocha.mojoskins.com/SharedFiles/Download.aspx?pageid=566&mid=786&fileid=38

http://weblogs.asp.net/infinitiesloop/TRULY-Understanding-Dynamic-Controls-_2800_Part-1_2900_

例は C# で書かれていますが、何が起こっているのかを理解できるはずです。結局のところ、これは同じ基本クラス ライブラリです。

于 2015-04-29T04:10:01.663 に答える