【问题标题】:Listview itemTemplate in ASP.NETASP.NET 中的列表视图项模板
【发布时间】:2010-12-28 16:05:27
【问题描述】:

我在获取 ASP 站点的列表视图权限时遇到了麻烦。我的数据如下:

所以我有一个包含统计列表的字典:

Dictionary<string, IList<Stats>>

Data example:   Key                Value
               Port1               List<Stats>: - int NumberOfSuspended
                                           |    - int NumberOfCompleted
                                           |------ string messagetype
               Port2               List<Stats>: -int numberOfSuspendes
                                           |    - int numberOfCompleted 
                                           |-----string messagetype

“stats”类包含几个变量(messagetype 和 numberofsuspended)

所以我需要创建一个如下所示的视图列表:

<table>
 <tr><td>Port1</td></tr>
  <tr><td>Messagetype</td><td>numberofSuspended</td>

 <tr><td>Port2</td></tr>
  <tr><td>Messagetype</td><td>numberofSuspended</td>
  .......
 </table>

所以基本上:字典中的 foreach 列表用 stats 属性排成一行(字典的键是 titlerow)

所以最终结果是这样的:

|----------------------------------------------
| PORT 1
|----------------------------------------------
|   MessageType1:   |   0/0 |   0/0
|----------------------------------------------
|   MessageType2:   |   0/0 |   0/0
|----------------------------------------------
|-----------------------------------------------
| PORT 2
|----------------------------------------------
|----------------------------------------------
|   MessageType1:   |   0/0 |   0/0
|----------------------------------------------
|   MessageType2:   |   0/0 |   0/0
|----------------------------------------------

谁能帮我解决列表视图的 itemTemplate 问题? 我认为这有点棘手,因为我使用字典? 我使用 DataBinding (Listview.Datasource = Dictionary<..>)

谢谢

【问题讨论】:

  • 您需要显示实际负责绑定的标记或代码隐藏。另一种尝试是订阅 OnItemDataBound 事件,使用 e.Row.FindControl("") 获取对当前行的 asp.net 元素的引用并为其分配值

标签: asp.net data-binding listview itemtemplate


【解决方案1】:

没有尝试过这个理论,但请告诉我你的想法:

您能否尝试添加一个占位符控件,循环遍历每个键并在循环中应用标题,并添加一个包含来自相应键的数据的中继器?

For each sKey as String in MyDictionary.Keys
  plcMyHolder.Controls.Add(New LiteralControl("<h1>" & sKey & "</h1>"))
  Dim rpt As New Repeater
  rpt.DataSource = MyDictionary(sKey)
  rpt.DataBind
  plcMyHolder.Controls.Add(rpt)
Next

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多