我想将Listview绑定到多个实体,所以我尝试做类似的事情,但我遇到两个问题:
<asp:ListView ID="lv_EmpSpecialVacations" runat="server" ItemPlaceholderID="RelationContainer" ItemType="Repositories.EmployeeSpecialHolidayRepository.AllIncluding(a=>a.SPECIALHOLIDAY).Where(a=>a.EMP_NUM == EmployeeNum);">
<LayoutTemplate>
<fieldset id="FieldSet1">
<legend>Relations</legend>
<br />
<a id="lbtnInitInsert" class="btn btn-primary btn-md white_cr" onclick="EditForInsert(this);"><span class="glyphicon glyphicon-plus-sign"></span></a>
<br />
<br />
<div class="container-fluid">
<div class="row">
<div class="col-lg-4">
END_DATE
</div>
<div class="col-lg-4">
HOLIDAY_NAME
</div>
<div class="col-lg-4">
</div>
</div>
</div>
<asp:PlaceHolder ID="RelationContainer" runat="server"></asp:PlaceHolder>
</fieldset>
</LayoutTemplate>
<ItemTemplate>
<div id="toappend">
</div>
<div class="container-fluid">
<div class="row">
<div class="col-lg-4 code">
<%#:Item.Select(a=>a.END_DATE)>
</div>
<div class="col-lg-4 name">
<%#:Item.Select(a=>a.SPECIALHOLIDAY.HOLIDAY_NAME)%>
</div>
<div class="col-lg-4">
<a id="lbtn_edit" class="btn btn-primary btn-md white_cr" onclick="Edit(this);"><span class="glyphicon glyphicon-pencil"></span></a>
</div>
</div>
</div>
</ItemTemplate>
</asp:ListView>
我想知道如何将ListView
绑定到多个实体而不会丢失strongly-typed binding?
答案 0 :(得分:1)
最简单的方法是创建一个&#34; union&#34;例如,使用两个公共属性(specialholiday和empspecialholiday)并将它们用于绑定。
答案 1 :(得分:1)
在SPECIALHOLIDAY
和EMPSPECIALHOLIDAY
之间会有一个关系,例如Holidayname
,所以通过在联合或内部联接中调用它,它将适用于你喜欢这个例子
联盟示例:
SELECT Holidayname FROM SPECIALHOLIDAY
UNION
SELECT Holidayname FROM EMPSPECIALHOLIDAY
ORDER BY Holidayname
内部加入示例:
SELECT * from SPECIALHOLIDAY as SP
inner join EMPSPECIALHOLIDAY as ES
on ES.Holidayname = SP.Holidayname
ORDER BY Holidayname
我认为这个例子可能适合你。