我正在採取一些代碼,我已經用於嵌套列表視圖之前,並試圖使其與嵌套Repeater工作,但我得到一個錯誤。嵌套中繼器錯誤:對象引用未設置爲對象的實例
System.NullReferenceException:未將對象引用設置爲對象的實例。
的.aspx
<asp:Repeater ID="reMainNav" runat="server">
<HeaderTemplate><ul></HeaderTemplate>
<ItemTemplate><li><%# DataBinder.Eval(Container.DataItem, "name")%>
<asp:Repeater ID="reSubNav" runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<%# DataBinder.Eval(Container.DataItem, "name")%>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</li></ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
的.vb
Protected Sub reMainNav_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles reMainNav.ItemDataBound
Dim rowView As System.Data.DataRowView
rowView = CType(e.Item.DataItem, System.Data.DataRowView)
'database connection from web.config file
Dim synergySQL As SqlConnection = New SqlConnection()
synergySQL.ConnectionString = ConfigurationManager.ConnectionStrings("connSynergy").ConnectionString()
'check if personal section complete
Dim cmdSubNav As SqlCommand = New SqlCommand()
cmdSubNav.Connection = synergySQL
cmdSubNav.CommandText = "SELECT * FROM [subNavigation] WHERE [parentId] = " & rowView("id") & " ORDER BY [orderNo]"
cmdSubNav.CommandType = CommandType.Text
'data adapter
Dim daSubNav As SqlDataAdapter = New SqlDataAdapter
daSubNav.SelectCommand = cmdSubNav
'data set
Dim dsSubNav As DataSet = New DataSet()
daSubNav.Fill(dsSubNav, "SubNav")
Dim iSchedule As Integer
iSchedule = dsSubNav.Tables(0).Rows.Count
Dim reSubNav As Repeater = CType(e.Item.FindControl("reSubNav"), Repeater)
reSubNav.DataSource = dsSubNav
reSubNav.DataBind()
synergySQL.Close()
End Sub
做我必須做一些事情的中繼器有什麼不同?
感謝您的任何幫助。
J.
調試代碼。處理異常的錯誤的更多細節..! – Muse