Vb.net嵌套转发器3级Handles子句需要一个WithEvents变量错误

时间:2017-04-13 22:26:17

标签: asp.net vb.net repeater

我正试图嵌套3个中继器以显示常见问题解答

分类

- 子类别

----问题

前两个中继器很好,但是当我尝试添加第三个中继器时

BC30506:Handles子句需要在包含类型或其基类型中定义的WithEvents变量。

aspx file 我无法将aspx文件粘贴到此编辑器上,因此上面是一个屏幕抓取

并且vb文件是

Partial Class ContactTest
Inherits System.Web.UI.Page
Public Conn As New SqlConnection(Utils.connString)
Sub Page_load()
    If Not Page.IsPostBack Then
        Conn.Open()
        FAQCatRep.DataSource = db.Open.DS("select * from FAQ_Category", Conn)
        FAQCatRep.DataBind()
        Conn.Close()
    End If
End Sub

Protected Sub FAQCatRep_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles FAQCatRep.ItemDataBound
    Select Case e.Item.ItemType
        Case ListItemType.Item, ListItemType.AlternatingItem

            Dim repFaqSub As Repeater = e.Item.FindControl("FAQSubCatRep")

            repFaqSub.DataSource = db.Open.DS("select * from FAQ_Sub_Category where Categoryid=" + e.Item.DataItem("ID").ToString(), Conn)
            repFaqSub.DataBind()

    End Select
End Sub

Protected Sub FAQSubCatRep_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles FAQSubCatRep.ItemDataBound
    Select Case e.Item.ItemType
        Case ListItemType.Item, ListItemType.AlternatingItem

            Dim repFaqQs As Repeater = e.Item.FindControl("QuestionRep")

            repFaqQs.DataSource = db.Open.DS("select * from FAQ where SubCatid=" + e.Item.DataItem("ID").ToString(), Conn)
            repFaqQs.DataBind()

    End Select
End Sub

结束班

FAQSubCatRep_ItemDataBound函数发生错误。

有没有人有任何想法?

感谢

搞定了。在第二个转发器内的aspx中添加了一个Literal来存储子类别id并将FAQCatRep_ItemDataBound函数更改为

   Protected Sub FAQCatRep_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles FAQCatRep.ItemDataBound
    Select Case e.Item.ItemType
        Case ListItemType.Item, ListItemType.AlternatingItem

            Dim repFaqSub As Repeater = e.Item.FindControl("SubFAQSubCatRep")

            repFaqSub.DataSource = db.Open.DS("select * from FAQ_Sub_Category where Categoryid=" + e.Item.DataItem("ID").ToString(), Conn)
            repFaqSub.DataBind()

            For Each subcat As RepeaterItem In repFaqSub.Items
                Select Case subcat.ItemType
                    Case ListItemType.Item, ListItemType.AlternatingItem
                        Dim qsub As Repeater = CType(subcat.FindControl("QuestionRep"), Repeater)
                        qsub.DataSource = db.Open.DS("select * from FAQ where SubCatid=" + CType(subcat.FindControl("SubCatgeoryIDltl"), Literal).Text, Conn)
                        qsub.DataBind()

                End Select
            Next
    End Select
End Sub

0 个答案:

没有答案