Binding object to RadGrid

2 posts, 0 answers
  1. sho
    sho avatar
    24 posts
    Member since:
    Mar 2007

    Posted 28 Jul 2011 Link to this post


    I have 2 class files.

    public class Employee
            public int EmpId { get; set; }
            public string EmpName { get; set; }
            public IList<Dept> DeptCollection { get; set; }

    public class Department
            public int DeptId { get; set; }
            public string DeptName { get; set; }

    I am fetching ILIST<Employee> and binding it to my radgrid.

    I want to display something like
    EmpId   EmpName   DeptName

    in the
    <telerik:GridBoundColumn ReadOnly="true" HeaderText="Employee Name"DataField="EMP_NAME" />

    but how can I bind the deptname field from the nested object?


  2. Daniel
    Daniel avatar
    4935 posts

    Posted 03 Aug 2011 Link to this post

    Hello Aradhya,

    I'm not sure that I understand your scenario completely. I imagine that you have a collection of Employees and each of these Employees has a separate Departments collection. How do you expect to show the DeptName string by linking a single item to a whole collection?

    Nevertheless, you can do something like this:
    <telerik:GridBoundColumn DataField="EmpId" />
    <telerik:GridBoundColumn DataField="EmpName" />
    <telerik:GridTemplateColumn UniqueName="">
            <%# GetDeptName(Eval("EmpId")) %>
    <telerik:GridEditCommandColumn />

    protected override void OnInit(EventArgs e)
        RadGrid1.NeedDataSource += (s, a) =>
                RadGrid1.DataSource = GetData();

    public string GetDeptName(object EmpId)
        int id = (int)EmpId;
        return GetData()...

    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. DevCraft R3 2016 release webinar banner
Back to Top