我有一个场景如下...... [英] i have a scenario below...

查看:78
本文介绍了我有一个场景如下......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实体类

i have a entity class

public class TransferHistory:StandardMaster
    {
        public ClientWorkStatus ClientWorkStatus { get; set; }

        public Role ROLE { get; set; }
        public Employee EMPLOYEE_ID { get; set; }
}





和公共员工EMPLOYEE_ID {get;组; },是一种EMPLOYEE类





and public Employee EMPLOYEE_ID { get; set; },is a Type of EMPLOYEE class

public class Employee : StandardMaster
    {
        public User USER { get; set; }
        public string USER_ID { get; set; }
        public Department DEPARTMENT { get; set; }

        public List<EmployeeToSkillSet> EmployeeToSkillSet { get; set; }
        public List<EmployeeToCountryRate> EmployeeToCountryRate { get; set; }
        public List<EmployeeFamily> EmployeeFamily { get; set; }

}





现在我必须绑定来自EmployeeToCountryRate的RATE(公共列表< employeetocountryrate> EmployeeToCountryRate) {get; set;})





now i have to bind RATE ,that from EmployeeToCountryRate(public List<employeetocountryrate> EmployeeToCountryRate { get; set; })

public class EmployeeToCountryRate:StandardMaster
    {
        public Country COUNTRY_ID { get; set; }
        public Decimal? RATE { get; set; }
    }



和我的Gridview是




and my Gridview is

<asp:GridView ID="gridReviewLog" runat="server" AutoGenerateColumns="false">
        <Columns>
            <asp:TemplateField HeaderText="Employee Name">
                <ItemTemplate>
                    <asp:TextBox ID="txtempname" runat="server" MaxLength="11" Value='<%#DataBinder.Eval(Container.DataItem,"EMPLOYEE_ID.Name") %>'  Enabled="false"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Employee Role">
                <ItemTemplate>
                    <asp:TextBox ID="txtrole" runat="server" Value='<%#DataBinder.Eval(Container.DataItem,"ROLE.Name") %>' MaxLength="11"  Enabled="false"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Actual Minute">
                <ItemTemplate>
                    <asp:TextBox ID="txtactualMin" runat="server"  Value='<%#DataBinder.Eval(Container.DataItem,"ACTUAL_MINUTES") %>' MaxLength="11"  Enabled="false"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Revised Minute">
                <ItemTemplate>
                    <asp:TextBox ID="txtrevisedmin" runat="server" MaxLength="11" Value='<%#DataBinder.Eval(Container.DataItem,"REVISED_MINUTES") %>' Enabled="true"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Employee Cost(per hour)">
                <ItemTemplate>
                    <asp:TextBox ID="cost" runat="server" MaxLength="11" Value='<%#DataBinder.Eval(Container.DataItem,"EMPLOYEE_ID.EmployeeToCountryRate.Select(x=>x.RATE)") %>' Enabled="false"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>



i必须在国家/地区费率字段中绑定,我该怎么办?做??欢迎提出建议,谢谢


i have to bind in Country Rate field, How can i do?? suggestions are welcome, thanks

推荐答案

假设您只想从列表中显示第一费率,请在<$中添加新属性c $ c>员工上课:

Assuming you just want to display the first rate from the list, add a new property to your Employee class:
public class Employee : StandardMaster
{
    ...
    public decimal? FirstRate
    {
        get
        {
            if (EmployeeToCountryRate == null) return null;
            if (EmployeeToCountryRate.Count == 0) return null;
            return EmployeeToCountryRate[0].RATE; 
        }
    }
}



然后你可以将 TextBox 绑定到新属性:


Then you can bind your TextBox to the new property:

<asp:TextBox ID="cost" runat="server" MaxLength="11" Value='<%# Eval("EMPLOYEE_ID.FirstRate") %>' Enabled="false" />






显示符合特定条件的单一费率,然后更新属性:




To display a single rate which matches a specific condition, then update the property:

public decimal? FirstRate
{
    get
    {
        if (EmployeeToCountryRate == null) return null;
        
        var theRate = EmployeeToCountryRate.FirstOrDefault(x => ???);
        return theRate == null ? null : theRate.RATE;
    }
}






如果要显示全部列表费率,那么你需要一个嵌套的数据绑定控件。例如:




If you want to display a list of all the rates, then you'll need a nested data-bound control. For example:

<asp:TemplateField HeaderText="Employee Cost(per hour)">
<ItemTemplate>
    <asp:ListView runat="server" DataSource='<%# Eval("EMPLOYEE_ID.EmployeeToCountryRate") %>'>
    <LayoutTemplate>
        <ul>
            <li id="itemPlaceholder" runat="server" />
        </ul>
    </LayoutTemplate>
    <ItemTemplate>
        <li>
            <asp:Literal runat="server" mode="encode"

                Text='<%# Eval("COUNTRY_ID.Name") %>'

            />
            =
            <asp:Literal runat="server" mode="encode"

                Text='<%# Eval("RATE", "{0:C}") %>'

            />
        </li>
    </ItemTemplate>
    </asp:ListView>
</ItemTemplate>
</asp:TemplateField>


这篇关于我有一个场景如下......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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