使用中继器,我遍历“SelectedUtility”表并输出匹配的位置。这可以正常工作,但是它会显示“Utility_Id”,它是实用程序表中“id”的外键。
我实际上想在实用程序表中显示“名称”列。我该怎么做...类似于<th style="width:200px;"><%# Eval("Utility_Id.name") %></th>
或是否在后面的代码中完成...感谢您的任何回复
aspx:
<asp:Repeater id="rptSelectedUtilities" runat="server">
<HeaderTemplate>
<table class="detailstable FadeOutOnEdit">
<tr>
<th style="width:200px;">Utility</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<th style="width:200px;"><%# Eval("Utility_Id") %></th>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
后面的代码:
DBData db = new DBDatat();
List<Select_Utility> SelectedUtility =
(from SU in db.Select_Utilities
where SU.Work_Id == 3
select SU).ToList();
rptSelectedUtilities.DataSource = SelectedUtility;
rptSelectedUtilities.DataBind();
编辑:
DBData db = new DBDatat();
List<Utility_Company> Utility = new List<Utility_Company>();
List<Select_Utility> SelectedUtility =
(from SU in db.Select_Utilities
join UTL in Utility on SU equals UTL.id
where SU.Worksite_Id == 3
select SU).ToList();
rptSelectedUtilities.DataSource = SelectedUtility;
rptSelectedUtilities.DataBind();
抛出错误“连接子句中的表达式之一的类型不正确。调用“加入”时类型推断失败
//应该加入名字..so join UTL in Utility on SU等于UTL.Name //而不是UTL.id
还尝试在 SU 上的 db.Utility_Companies 中加入 UTL 等于 UTL.id ...但同样的错误
第二次编辑:<%# Eval("Name") %> 抛出错误:DataBinding: 'Select_Utility' 不包含名为 'Name' 的属性。
DBData db = new DBData();
List<Select_Utility> SelectedUtility =
(from SU in db.Select_Utilities
where SU.Worksite_Id == 3
select SU).ToList();
rptSelectedUtilities.DataSource = SelectedUtility;
rptSelectedUtilities.DataBind();
List<Utility_Company> Utility = new List<Utility_Company>();
var query = from u in db.Utility_Companies
join su in db.Select_Utilities
on u.id equals su.Utility_Id
where su.Worksite_Id == 3
select u;
rptSelectedUtilities.DataSource = query.ToList();
rptSelectedUtilities.DataBind();