谁做过类似树形论坛的列表?

gui1401 2007-04-19 03:56:42
我想做个列表控件,列表的第一列前面有个加号“+”,点加号,显示对应这条数据的详细内容,点“+”前,这部分内容是隐藏的。
最好能多层嵌套。
给个思路也行。
效果就像下面这个论坛:
http://bbs.e23.cn/list.asp?boardid=15
...全文
236 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
andyhooo 2007-04-19
  • 打赏
  • 举报
回复
没做过./学习
zhilaizhiw 2007-04-19
  • 打赏
  • 举报
回复
使用DataList嵌套实现树型结构显示数据。注意:微软提供的TreeView控件可以很好地实现树型结构,但它只提供每个叶子节点只显示一列数据的功能。使用DataList嵌套,可以实现树型数据的多列显示功能。这里只提供部分代码,有兴趣研究可以找我。

#Region "Using ItemCommand to start to bind child DataList"
Private Sub dlstGroup_ItemCommand(ByVal [source] As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlstGroup.ItemCommand
'-----------------------------------------------
'Show the child datalist and bind it.
'-----------------------------------------------
If (e.CommandName = "carryout") Then
For Each dgi As DataListItem In Me.dlstGroup.Items
'Only find the current item's child datalist.
If (dgi.ItemIndex = e.Item.ItemIndex) Then
Dim lb As Label = CType(dgi.FindControl("lblMyClientCode"), Label) 'find clientcode lable.
Dim objDataList As DataList = CType(dgi.FindControl("dlstChild"), DataList) 'find the child datalist.
Dim imgBtnOut As ImageButton = CType(dgi.FindControl("imgbtnPlus"), ImageButton) 'find the imgbtn "+"
Dim imgBtnIn As ImageButton = CType(dgi.FindControl("imgbtnFminus"), ImageButton) 'find the imgbtn "-"
Dim strClientCode As String

'find the lable whose text is the clientcode.
If Not (lb Is Nothing) Then
strClientCode = lb.Text.Trim()
End If
'Bind the child datalist if find it.
If Not (objDataList Is Nothing) Then
objDataList.Visible = True
Try
BindDataListChild(objDataList, strClientCode, ViewState("ProjectCode"), ViewState("Range"), ViewState("NiHon"), ViewState("DelFlag"))
Catch ex As Exception
Response.Redirect(lStrErorrPage)
'add log
End Try
End If
'Set the imagebtn's property.
If Not (imgBtnOut Is Nothing) Then
imgBtnOut.Visible = False
End If
If Not (imgBtnIn Is Nothing) Then
imgBtnIn.Visible = True
End If
End If
Next
End If
'-----------------------------------------------
'Unvisible the child datalist
'-----------------------------------------------
If (e.CommandName = "carryin") Then
For Each dgi As DataListItem In Me.dlstGroup.Items
'find the child data list in the just item,and set the unvisible property.
If (dgi.ItemIndex = e.Item.ItemIndex) Then
Dim objDataList As DataList = CType(dgi.FindControl("dlstChild"), DataList) 'find the child datalist.
Dim imgBtnOut As ImageButton = CType(dgi.FindControl("imgbtnPlus"), ImageButton) 'find the imgbtn "+"
Dim imgBtnIn As ImageButton = CType(dgi.FindControl("imgbtnFminus"), ImageButton) 'find the imgbtn "-"

objDataList.Visible = False
If Not (imgBtnOut Is Nothing) Then
imgBtnOut.Visible = True
End If
If Not (imgBtnIn Is Nothing) Then
imgBtnIn.Visible = False
End If

End If
Next
End If
End Sub
#End Region

这里使用DataList的ItemCommand事件,来执行展开嵌套子DataList的代码。需要说明一下,这里的主要思路是通过分别绑定父和子两个不同的DataList来实现树型展开。当点击具有“carryout”命令的“+”图片时,根据此时的父DataList的参数,来绑定子DataList。另外,可以通过把子DataList放在ItemTemplet或者EditTemplet来决定是否可以同时展开多个子节点。
另外说一下,不一定非要datalist套datalist,datagrid套datalist也是可以得,或者gridview什么的。思路都一样,可以灵活运用。
seesea125 2007-04-19
  • 打赏
  • 举报
回复
ajax+div,点加号时,使用ajax从服务器调数据过来,然后绑定到repeater中,注意这个repeater是在DIV中的,然后把这个DIV的属性设置成可见
gui1401 2007-04-19
  • 打赏
  • 举报
回复
不是菜单,是列表,有多列。
动网的那个效果
confei 2007-04-19
  • 打赏
  • 举报
回复
菜单树?

62,056

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧