Adding Telerik controls dynamically on a page

5 posts, 0 answers
  1. Deep Ghosh
    Deep Ghosh avatar
    7 posts
    Member since:
    Feb 2010

    Posted 13 Aug 2012 Link to this post

    I have a Page which has a HEADER section. Once information is filled up, I want to display a Grid control on the bottom half of a page.
    How do I achieve this in ASP.NET AJAX.

    The Grid Control contains Combo Boxes and Check Boxes.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Aug 2012 Link to this post

    Hi Deep,

    You can add a RadGrid dynamically as shown below.
    C#:
    protected void Page_Init(object sender, System.EventArgs e)
    {
      RadGrid1 = new RadGrid();
      RadGrid1.ID = "RadGrid1";
      PlaceHolder1.Controls.Add(RadGrid1);
      RadGrid1.MasterTableView.DataKeyNames = new string[] { "EmployeeID" };
      RadGrid1.MasterTableView.AutoGenerateColumns = false;
      GridBoundColumn boundColumn;
      boundColumn = new GridBoundColumn();
      NewTemplateColumn templateColumn = new NewTemplateColumn();
      templateColumn.ItemTemplate = new TemplateColumn();
      RadGrid1.MasterTableView.Columns.Add(templateColumn);
      GridBoundColumn boundColumn1 = new GridBoundColumn();
      boundColumn1.DataField = "ContactName";
      boundColumn1.UniqueName = "ConactName";
      boundColumn1.HeaderText = "Bound Column";   
      RadGrid1.MasterTableView.Columns.Add(boundColumn);
      boundColumn.DataField = "EmployeeID";
      boundColumn.HeaderText = "EmployeeID";
      boundColumn.DataType = typeof(System.Decimal);
      boundColumn = new GridBoundColumn();
      RadGrid1.MasterTableView.Columns.Add(boundColumn);
    }
    public partial class TemplateColumn : ITemplate //adding template fields
    {
      public void InstantiateIn(Control container)
      {
        CheckBox chk = new CheckBox();
        chk.ID = "CheckBox1";
        container.Controls.Add(chk);
               
      }
    }
    Also check the following help documentation which explains more about this.
    Programmatic Creation.

    Thanks,
    Shinu.
  3. Deep Ghosh
    Deep Ghosh avatar
    7 posts
    Member since:
    Feb 2010

    Posted 16 Aug 2012 Link to this post

    Hello,
    That code is fine to add on Page_INIT.
    We already have some controls on the screen.
    Then when user presses a button, We want to add the grid. Attached is a sample of such screen. Top part is the initial display. Bottom part needs to be added dynamically.
    Please help us on how to do this.
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Aug 2012 Link to this post

    Hi,

    You can add a div and style it accordingly to show the grid at the bottom.
    aspx:
    <div id="div1" runat="server" style="margin-top:500px">
    </div>
    C#:
    div1.Controls.Add(RadGrid1);

    Thanks,
    Shinu.
  5. Deep Ghosh
    Deep Ghosh avatar
    7 posts
    Member since:
    Feb 2010

    Posted 07 Sep 2012 Link to this post

    Hi Shinu,

    Thanks for earlier reply. 
    Basically we want to generate the grid dynamically and add to the page on some action such as button click with no page refresh.

    - a  aspx page with RadGird  is called and the output is sent back through web method and displayed. This is displaying the radgrid but the add record and column re-oriding throws error due to corruption in viewstate.

    Another option we tried is - a dynamic grid is being created and then using rendercontrol method trying to get the html.
    The html code is genereated but only a black box is appearing and not the grid.( Radgrid is added to a panel and panel is added to a page and panel.RenderControl is being done).

    - Please let us know which method to use and how to resolve the issue in each approach or is there any other apporach.
    I can provide a sample code . Please let me know your email id.

    Regards,
    Deep
Back to Top