当前位置:首页 >设计资讯> 正文

vb.net中Repeater嵌套Repeater

文章来源: 发布时间: 2017-12-24

代码部份:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)  
 Dim str As String = "select * from 你的表" 
 mynews1.DataSource = dbopen(Str)
 mynews1.DataBind()
End Sub
’读取子栏目
Sub Item_Bound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
     Dim str2 As String = "select *  from 你的表 where 关联字段=" & e.Item.DataItem("web_id") & " order by px"
     Dim xRepeater As Repeater = CType(e.Item.FindControl("mynews2"), Repeater)
     xRepeater.DataSource = dbopen(str2)
     xRepeater.DataBind()
End Sub
function dbopen(str as string)
 dim myvar as string=configurationsettings.appsettings("connstring") 
 dim conn as oledbconnection=new oledbconnection("provider=microsoft.jet.oledb.4.0;data source="&server.MapPath(myvar)) 
 dim comm as oledbdataAdapter=new oledbdataAdapter(str,conn)
 dim ds as new dataset
 comm.fill(ds,"biao")
 dbopen = ds.Tables("biao").DefaultView
end function
应用部份:
  <asp:Repeater ID="mynews1"  runat="server" OnItemDataBound="Item_Bound">
 <itemtemplate> 
 <%# eval("表一字段")%>
 <asp:Repeater ID="mynews2" runat="server">
  <itemtemplate>
   <%# eval("表二字段")%>
  </itemtemplate>
 </asp:Repeater>                              
 </itemtemplate>
</asp:Repeater>