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

Adding Telerik controls dynamically on a page

4 Answers 388 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Deep Ghosh
Top achievements
Rank 1
Deep Ghosh asked on 13 Aug 2012, 05:47 PM
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.

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Aug 2012, 05:37 AM
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.
0
Deep Ghosh
Top achievements
Rank 1
answered on 16 Aug 2012, 11:28 PM
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.
0
Shinu
Top achievements
Rank 2
answered on 17 Aug 2012, 07:38 AM
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.
0
Deep Ghosh
Top achievements
Rank 1
answered on 07 Sep 2012, 07:52 PM
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
Tags
General Discussions
Asked by
Deep Ghosh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Deep Ghosh
Top achievements
Rank 1
Share this question
or