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

Binding the SubObjects to the radgrid

3 Answers 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mesha
Top achievements
Rank 1
mesha asked on 21 Oct 2008, 04:45 PM
Hi,

Is it possible to assign the subobjects along with the main object to the radgrid?

Following is my problem which i was unable to resolve...Kindly help me....

I have a "Document Object" which contains following properties

DocumentID
DocumentName
TemplateID
objTemplate

I have another object called "Template" which contains the following properties
TemplateID
TemplateName
Field1
Field2

***Template object exist for every document object and here I am assigning the datasource as Document Object to the Radgrid.

Now i would like to display in the following format which includes Document properties and template properties.

DocumentID
DocumentName
TemplateID
TemplateName
Field1
Field2

I have tried with somany tricks and unfortunately i was not success to solve my problem.

I would appreciate if you could help me in this problem.

PS: If possible please post the code as well.

Many Thanks,
S

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 22 Oct 2008, 06:43 AM
Hello,

Please check this example for more info:
http://demos.telerik.com/aspnet/Prometheus/Grid/Examples/Programming/Binding/DefaultCS.aspx

Greetings,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
mesha
Top achievements
Rank 1
answered on 22 Oct 2008, 03:38 PM
Hi Vlad,

Many Thanks for your quick reply..

Unfortunately, this example is not solving my problem...as i mentioned that i have a object with in another object.

I believe VB.NET does not support operator overloading for which we can add 2 class objects to make it as one object.

I would appreciate if you could send me solution to my problem.

I have a "Document Object" which contains following properties

DocumentID
DocumentName
TemplateID
objTemplate is of type Template

I have another object called "Template" which contains the following properties

TemplateID
TemplateName
Field1
Field2

Now i would like to display in the following format which includes Document properties and template properties.

DocumentID
DocumentName
TemplateID
TemplateName
Field1
Field2

Please post me some code..

Many Thanks,
Shashi
0
Princy
Top achievements
Rank 2
answered on 23 Oct 2008, 07:35 AM
Hello,

Check out the code below I implemented taking your scenario into account. Hope this explains what you are looking for.
Template Class:
namespace Document 
    public class Template 
    { 
 
        private string _field1; 
        private string _field2; 
 
        public string Field1 
        { 
            get 
            { 
                return _field1; 
            } 
            set 
            { 
                _field1 = value
            } 
 
        } 
 
        public string Field2 
        { 
            get 
            { 
                return _field2; 
            } 
            set 
            { 
                _field2 = value
            } 
 
        } 
    } 
 

Document Class:
namespace Document 
 
    public class Document 
    { 
        public Document() 
        { 
            // 
            // TODO: Add constructor logic here 
            // 
        } 
 
        private Template _template; 
 
 
        public Template Temp 
        { 
            get 
            { 
                return _template; 
            } 
 
            set 
            { 
                _template = value
            } 
        }        
    } 

cs: 
namespace Document 
    public partial class _Default : System.Web.UI.Page 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            Document doc = new Document(); 
            Template temp = new Template();             
            temp.Field1 = "field1"
            temp.Field2 = "field2"
 
            doc.Temp = temp
 
 
            Document doc1 = new Document(); 
            Template temp1 = new Template(); 
            temp1.Field1 = "field3"
            temp1.Field2 = "field4";             
 
            doc1.Temp = temp1
 
 
            IList<Document> list = new List<Document>(); 
 
            list.Add(doc); 
            list.Add(doc1); 
 
            RadGrid1.DataSource = list
            RadGrid1.DataBind(); 
 
        } 
    } 

You can labels to the TemplateColumns and bind them as shown below
aspx:
<telerik:radgrid id="RadGrid1" runat="server" autogeneratecolumns="False" gridlines="None"
         <MasterTableView> 
         <Columns> 
         <telerik:GridTemplateColumn> 
         <ItemTemplate> 
                        <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"temp.Field1") %>'></asp:Label> 
                    </ItemTemplate> 
         </telerik:GridTemplateColumn> 
         <telerik:GridTemplateColumn> 
         <ItemTemplate> 
                        <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"temp.Field2") %>'></asp:Label> 
                    </ItemTemplate> 
         </telerik:GridTemplateColumn> 
         </Columns> 
            .... 

Thanks
Princy.
Tags
Grid
Asked by
mesha
Top achievements
Rank 1
Answers by
Vlad
Telerik team
mesha
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or