【发布时间】:2009-05-03 14:00:33
【问题描述】:
我想使用嵌套的 ListView 控件实现 this article 中提到的外观。但是,在我的场景中,我不能使用 EntityDataSource 控件,所以我手动绑定数据。
我的桌子:
Categories
PK: UniqueId, Guid
Name, string
ParentId, Guid
<asp:ListView ID="CategoryList" runat="server"
onitemdatabound="CategoryList_ItemDataBound">
<LayoutTemplate>
<table>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td colspan="2"><%# Eval("Name") %></td>
</tr>
</ItemTemplate>
</asp:ListView>
protected void Page_Load(object sender, EventArgs e)
{
using (PractiseEntities context = new PractiseEntities()) {
var result = from categories in context.Categories
select categories;
CategoryList.DataSource = result;
CategoryList.DataBind();
}
}
我希望通过在“ParentId”不为空的项目中添加<td> 标记来使子类别缩进。而我的问题是如何在ItemDataBound事件中编辑生成的html标签?
【问题讨论】:
标签: asp.net data-binding listview