Click here to Skip to main content
15,915,702 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a entity class
C#
public class TransferHistory:StandardMaster
    {
        public ClientWorkStatus ClientWorkStatus { get; set; }

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


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

C#
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; }

}


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

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

and my Gridview is

XML
<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 have to bind in Country Rate field, How can i do?? suggestions are welcome, thanks
Posted
Comments
Richard Deeming 28-Aug-14 8:35am    
Even if DataBinder.Eval supported calling extension methods (which it doesn't), your Select call would return multiple values per row. You're then trying to display those values in a single TextBox, which can only have a single value.

What value are you expecting to see in the TextBox?
Xavier Nishanth 28-Aug-14 8:39am    
yeah.. thats just mad thing, i just used SELECT because others to understand.
I need to display RATE thats in EmployeeToCountryRate class. it refer as Ltst of objects in EMPLOYEE class.

EMPLOYEE_ID.EmployeeToCountryRate is List, i need to show Rate thats inside that LIST

And Thanks for da reply.
Richard Deeming 28-Aug-14 8:41am    
Yes, I understand that it's a list, but I'm asking you which rate you want to display. You can't display ten values in a single TextBox!
Xavier Nishanth 28-Aug-14 8:43am    
yeah its single value with Unique Country ID, if CountryID="US", i have to display US rate.

1 solution

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

Then you can bind your TextBox to the new property:
ASP.NET
<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:
C#
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.NET
<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>
 
Share this answer
 
v3
Comments
Xavier Nishanth 28-Aug-14 8:51am    
Thats better but is there any bind a object from a list inside another list??
Richard Deeming 28-Aug-14 8:53am    
Are you saying you want a list of all the rates within the GridView cell?
Xavier Nishanth 28-Aug-14 9:00am    
No. that list contain only 2 rates i just wanna display one Rate in a textbox with condition .

in linq EmployeeToCountryRate.Where(x=> x.Country == "US").select(x=>x.RATE).FirstOrDefault()

this will return Rate (int) and i have to display in TEXTBOX
Richard Deeming 28-Aug-14 9:02am    
Then change the condition within the property.
Xavier Nishanth 28-Aug-14 9:04am    
im binding GridView With List
gridReviewLog.DataSource = listTransHistory;
gridReviewLog.DataBind();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900