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

How to bind RadGrid with custom DataTable

5 Answers 943 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jeremie
Top achievements
Rank 1
jeremie asked on 05 Sep 2017, 02:26 PM

hi there,

Please help me to setup my RadGrid.

My scenario is : I click on a linkbutton with a navigateUrl which contains parameters I need to Load the RadGrid. With that parameter, I can load my list of Entities.

But the visual representation of theses datas, is not a classical RadGrid with properties columns binding.

In fact, I need to Bind each Entity into a Cell of my RadGrid. How can I realise it ?

I am trying this code :

public void Loading()

{

            List<T> entities = getFromDb(); // T is my complex Object

            // Determine what will be the rows
            List<string> rows = entities.Select(e => e.X_MyProperty).Distinct().ToList();

              // Determine what will be the columns
            List<string> columns = entities.Select(e => e.Y_MyProperty).Distinct().ToList();
            
            DataTable table = new DataTable();

            table.Columns.Add("FirstColumn");

            foreach (string columnsName in columns)
            {
                   table.Columns.Add(columnsName);
            }

            foreach (var row in rows)
            {
                TableRow r = new TableRow();
                table.Rows.Add(r);
                r.Cells.Add(new TableCell {Text = row });

                for (int i = 0; i < columns.Count; i++)
                {
                    var c = new TableCell();
                    r.Cells.Add(c);

                    c.Controls.Add(new Label { Text = "A Property of T to display" });
                }
            }

            GridDetailEmplacements.DataSource = table;
            GridDetailEmplacements.DataBind();

}

 

Inside the ASPX file : 

 <telerik:RadGrid runat="server" ID="GridDetailEmplacements" AutoGenerateColumns="False">
                        <ClientSettings ReorderColumnsOnClient="false" AllowColumnsReorder="false">
                            <Selecting AllowRowSelect="false" EnableDragToSelectRows="false" />
                            <Resizing AllowColumnResize="false" ResizeGridOnColumnResize="false" AllowResizeToFit="false" />
                        </ClientSettings>

                        <HeaderStyle HorizontalAlign="Center" Font-Size="14px"></HeaderStyle>
                        <ItemStyle HorizontalAlign="Left" Font-Names="Arial Unicode MS" Font-Size="12px" />
                        <AlternatingItemStyle HorizontalAlign="Left" Font-Names="Arial Unicode MS" Font-Size="12px" />

                    </telerik:RadGrid>

How can I Bing different properties of my Object of T inside each cells ?

I would like render acell with a simple asp:Table which contains 3 rows with 3 properties of my Object

 

Thank's for helping 

 

Best regards

5 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 08 Sep 2017, 10:21 AM
Hi Jeremie,

In order to achieve this requirement you should follow the steps provided in the following article:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/changing-the-grid-structure-dynamically-on-postback

And for the complex cell you can use GridTemplateColumn. Programmatic creation of template columns is demonstrated in this section:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/creating-a-radgrid-programmatically#creating-template-columns-programmatically

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
jeremie
Top achievements
Rank 1
answered on 08 Sep 2017, 12:12 PM

Hi Eyup,

Thanks for your help. Indeed, I had already found the "GridTemplateColum Guide" and It works :)

In fact, I solved my issue by try a lot of differents approches.

So I combine GridTemplateColum (create programatically) with my DataSource and it's OK

Best regards

0
jeremie
Top achievements
Rank 1
answered on 11 Sep 2017, 03:10 PM

I am now trying to replace my old InstantiateIn(Control container) method which was :

  RenderedTable = new Table();
            container.Controls.Add(RenderedTable);

            var row = new TableRow();
            RenderedTable.Rows.Add(row);

            var cell = new TableCell();
            row.Cells.Add(cell);
            Btn = new Button { CssClass = "BtnEmplacementKey" };
            Btn.DataBinding += Btn_DataBinding;
            cell.Controls.Add(Btn);

 

 

By a new ASCX control like :

 var userControl = new EmplacementUserInterface();
            container.Controls.Add(userControl);

 

But, at render, nothing appear. 

 

Why ?

0
Eyup
Telerik team
answered on 14 Sep 2017, 09:02 AM
Hello Jeremie,

Please open a formal support ticket to send us a very basic runnable web site sample to demonstrate the issue so we can further investigate the case.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
jeremie
Top achievements
Rank 1
answered on 14 Sep 2017, 09:17 AM

Thanks for reply.

 

I solved my issue myself : 

 

 public virtual void InstantiateIn(Control container)
        {

            //FromMyPage is the calling Page instance
            var userControl = (MyUserControlClass)FromMyPage.LoadControl(UserControlPath); 
            container.Controls.Add(userControl);
        }

Tags
Grid
Asked by
jeremie
Top achievements
Rank 1
Answers by
Eyup
Telerik team
jeremie
Top achievements
Rank 1
Share this question
or