如何绑定属性存在于ListView
控件中的相关实体中:
<asp:ListView ID="lv_science_degree" runat="server" ItemPlaceholderID="scienceDegreeContainer" ItemType="DomainClasses.SCIENCEDEGREE" >
<LayoutTemplate>
<fieldset id="FieldSet1">
<legend>Science Degree </legend>
<div class="container-fluid">
<div class="row">
<div class="col-lg-3">
CODE
</div>
<div class="col-lg-3">
NAME
</div>
<div class="col-lg-3">
CATEGORY
</div>
<div class="col-lg-3">
</div>
</div>
</div>
<asp:PlaceHolder ID="jobDegreeCategoryContainer" runat="server"></asp:PlaceHolder>
</fieldset>
</LayoutTemplate>
<ItemTemplate>
<div id="toappend">
</div>
<div class="container-fluid">
<div class="row">
<div class="col-lg-3 code">
<%#:Item.SDEGREE_CODE%>
</div>
<div class="col-lg-3 name">
<asp:Label ID="lbl_degree_name" Class="lbl_degree_name" runat="server" Text="<%#:Item.DEGREE_NAME.Trim()%>"></asp:Label>
<asp:TextBox ID="txt_degree_name" Class="txt_degree_name HideElement" runat="server" Text="<%#:Item.DEGREE_NAME.Trim()%>"></asp:TextBox>
</div>
<div class="col-lg-3 cat">
<asp:RadioButtonList ID="rbl_degree" runat="server"></asp:RadioButtonList>
<asp:Label ID="lbl_degree_cat" Class="lbl_degree_cat" runat="server" Text="<%#:Item.SCATEGORY_CODE%>"></asp:Label> <%-- Want To Bind to QUALCATEGORY Entity to Bind to the Name instead of the code --%>
</div>
<div class="col-lg-3">
<a id="lbtn_edit" class="btn btn-primary btn-md white_cr" onclick="Edit(this);"><span class="glyphicon glyphicon-pencil"></span></a>
<a id="lbtn_update" class="btn btn-primary btn-md white_cr HideElement lbtn_update" onclick="Update(this);">update</a>
<a id="lbtn_cancel" class="btn btn-primary btn-md white_cr HideElement lbtn_cancel" onclick="Cancel(this);">cancel</a>
<a id="lbtn_delete" class="btn btn-primary btn-md white_cr HideElement lbtn_delete" onclick="Delete(this);">delete</a>
</div>
</div>
</div>
</ItemTemplate>
</asp:ListView>
在这里,我想将列表视图绑定到QUALCATEGORY
与 SCIENCEDEGREE
结合,以便我可以绑定标签lbl_degree_cat
CategoryName
属性存在于QUALCATEGORY
实体中,而不是CategoryCode
实体中的SCIENCEDEGREE
。
修改
我的绑定方法:
<。>在.cs文件中我在(!IsPostBack)
中调用以下方法
protected void GetAllScienceDegrees()
{
using (scienceDegreeRepository repo= new scienceDegreeRepository ())
{
lv_science_degree.DataSource = repo.All.ToList();
lv_science_degree.DataBind();
}
}