This is a migrated thread and some comments may be shown as answers.

Binding object to RadGrid

1 Answer 28 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
sho
Top achievements
Rank 1
sho asked on 28 Jul 2011, 08:07 AM
Hi,

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?

Regards,
aradhya
           



1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 03 Aug 2011, 03:05 PM
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="">
    <ItemTemplate>
        <%# GetDeptName(Eval("EmpId")) %>
    </ItemTemplate>
</telerik:GridTemplateColumn>
<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()...
}

Regards,
Daniel
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.

Tags
General Discussions
Asked by
sho
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or