EF,将列与2个字段连接起来。 [英] EF, concatenate a column with 2 fields.

查看:97
本文介绍了EF,将列与2个字段连接起来。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有办法在DataGrid列上的导航键中添加值,该列绑定到其实体容器字段中的字段。这听起来很难描述!



我有一个持有重量的字段,同一个表有一个重量类型的参考表,即lbs,kgs等...所以我想要列到显示6公斤而不是6元。



我的第一个想法:



Is there a way to add the value from a navigation key on a DataGrid column that is bound to a field from it''s Entity container field. This sounds hard to describe!

I have a field that holds a weight, same table has a referenced table for types of weight i.e. lbs, kgs, etc... So I want the column to show 6kg instead of 6.

My first idea:

<asp:BoundColumn DataField="Weight" DataFormatString="{0:<%# Eval("WeightType.WeightType") %>}" HeaderText="Weight ></asp:BoundColumn>





我知道非法因为全部退出,所以有没有办法连接这个?



I know illegal as all get out, so is there a way to concatenate this?

推荐答案

只是搞乱我发现你可以使用ItemTemplate并添加2个标签,中提琴!希望这有助于其他人。



Just messing around I found you can use the ItemTemplate and add 2 labels, viola! Hope this helps someone else.

<asp:templatecolumn>
                <HeaderTemplate>
                  <asp:label id="lbHeader" runat="server" text="Weight" />
                </HeaderTemplate>
                <itemtemplate>
                  <asp:label id="lbWeight" runat="server" text="<%# Bind("Weight") %>" />
                  <asp:label id="lbWeightType" runat="server" text="<%# Bind("Weight.WeightType") %>" />
                </itemtemplate>
              </asp:templatecolumn>





我现在需要的是一个更好的搜索标题。

这篇关于EF,将列与2个字段连接起来。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆