我有来自数据库的记录,由部门分隔,我想在不同的表(每个部门)内水平地平铺它们。这是我尝试过的(这不起作用)
.aspx的
<asp:ListView ID="lvUnderwriting" GroupItemCount="6" runat="server" GroupPlaceholderID="grpPlaceHolder1" ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<table>
<asp:PlaceHolder ID="grpPlaceHolder1" runat="server" ></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<span><b><%# Eval("gensubbusiclass") %></b></span>
<table>
<tr>
<th>Role Name:</th>
<th>Pending Tasks:</th>
<th>On Leave:</th>
</tr>
<tr>
<asp:PlaceHolder ID="itemPlaceHolder1" runat="server"></asp:PlaceHolder>
</tr>
</table>
</GroupTemplate>
<ItemTemplate>
<tr>
<td><span> <%#Eval("RoleName") %></span></td>
<td><span><%# Eval("Count") %></span></td>
<td><span><%# Eval("OnLeave") %></span></td>
</tr>
</ItemTemplate>
</asp:ListView>
数据库行
我目前的结果。由于某种原因,第二部门分为两个表。另外我如何水平平铺它们?
答案 0 :(得分:0)
好的,我得到的是ListView无法显示开箱即用的主要详细记录。这是我试图让它为我工作。诀窍是如果标题数据绑定项被更改,则动态地向表添加新行,数据库记录需要提前排序才能使其正常工作。从这里引用using Asp.net 3.5 ListView 4 Guys from Rolla
.aspx的
<asp:ListView ID="lvUnderwriting" runat="server" ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<table border="1" cellpadding="4px">
<tr>
<th>Role Name:</th>
<th>Assigned:</th>
<th>On Leave:</th>
</tr>
<tr>
<asp:PlaceHolder ID="itemPlaceHolder1" runat="server" />
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<%# AddGroupUnderwriting() %>
<td><%# Eval("RoleName") %></td>
<td><%# Eval("Count") %></td>
<td><%# Eval("OnLeave") %></td>
</tr>
</ItemTemplate>
</asp:ListView>
C#
// Add group row to underwriting grid
private string prevUWBusinessClass = "";
public string AddGroupUnderwriting()
{
string currentUWBusinessClass = Eval("gensubbusiclass").ToString();
if (currentUWBusinessClass != prevUWBusinessClass)
{
prevUWBusinessClass = currentUWBusinessClass;
return string.Format(@"<tr><td colspan=""3""><h3>Department: {0}</h3></td></tr>", currentUWBusinessClass);
}
else
return "";
}