How to bind RadGrid with custom DataTable

6 posts, 0 answers
  1. jeremie
    jeremie avatar
    4 posts
    Member since:
    Apr 2015

    Posted 05 Sep 2017 Link to this post

    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

  2. Eyup
    Admin
    Eyup avatar
    3825 posts

    Posted 08 Sep 2017 Link to this post

    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.
  3. jeremie
    jeremie avatar
    4 posts
    Member since:
    Apr 2015

    Posted 08 Sep 2017 Link to this post

    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

  4. jeremie
    jeremie avatar
    4 posts
    Member since:
    Apr 2015

    Posted 11 Sep 2017 Link to this post

    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 ?

  5. Eyup
    Admin
    Eyup avatar
    3825 posts

    Posted 14 Sep 2017 Link to this post

    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.
  6. jeremie
    jeremie avatar
    4 posts
    Member since:
    Apr 2015

    Posted 14 Sep 2017 Link to this post

    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);
            }

Back to Top