【发布时间】:2011-02-04 15:08:43
【问题描述】:
我在将一些数据绑定到 ASP.NET 中的列表视图时遇到问题。 我正在制作一个数据库管理页面,我可以在其中从组合框中的数据库中选择一个表。 当您选择表格时,会出现一个列表视图,其中包含该表格的所有数据。现在我想使用数据绑定,但我真的不知道如何处理。
<asp:ListView ID="lvData" runat="server">
<LayoutTemplate>
<table class="tableresults">
<thead>
<tr class="odd">
<th>
<%# Eval('COLUMNTITLE') %>
</th>
</tr>
</thead>
<tbody>
<asp:PlaceHolder ID="ItemPlaceHolder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<th scope="row">
<%# Eval('PROPERTY') %>
</th>
</tr>
</ItemTemplate>
</asp:ListView>
所以基本上我需要在 layouttemplate 和 itemtemplate 中进行某种循环,循环遍历从数据库中获取的数据的“列标题”和“值”。 我可以通过数据绑定来实现吗?
所以我只使用这样的代码:
lvData.DataSource = getData();
lvData.DataBind();
谢谢
【问题讨论】:
-
你真的在使用 MVC 吗?这看起来不像 MVC。
-
是的,我简化了一些代码来提出我的问题,我正在处理视图,但我认为这与我的问题无关,我看看我是否可以取消标记 aps.net-mvc标记。
标签: c# asp.net data-binding