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

[Solved] Adding columns to grid in codebehind

3 Answers 213 Views
Grid
This is a migrated thread and some comments may be shown as answers.
anna
Top achievements
Rank 1
anna asked on 01 May 2008, 02:36 PM
I am using RadTabStrip and I have a radgrid in one of my  pageview control. I want to add data columns in that grid in my codebehind file. How do i do that.

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 01 May 2008, 03:00 PM
Hi anna,

We would suggest you to review this documentation article here to get you started.

Hope this helps.


Kind regards,
Maria Ilieva
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
anna
Top achievements
Rank 1
answered on 01 May 2008, 04:01 PM
problem is, I placed a grid in my pageview and I am trying to programmatically add columns in it: my code is

Dim sConnectionString As String = "conn ..."

con.ConnectionString = sConnectionString

con.Open()
and i get data in my array. and i am binding this data to gidcolumns:

Dim

boundColumn As GridBoundColumn

boundColumn =

New GridBoundColumn

boundColumn.DataField = orderdata(11)

boundColumn.HeaderText =

"data"

RadGrid1.MasterTableView.Columns.Add(boundColumn)
but I dont see my grid during run time at all.

0
Princy
Top achievements
Rank 2
answered on 02 May 2008, 05:27 AM

Hi Anna,

To define the structure of a RadGrid control that is declared in the ASPX page, use the Page_Load event handler. Columns and detail table should be added to the corresponding collection first, before the values for their properties are set.

CS:

private void Page_Load(object sender, System.EventArgs e)  
{  
  if ( !IsPostBack )  
  {  
    GridBoundColumn boundColumn;  
 
    //Important: first Add column to the collection  
    boundColumn = new GridBoundColumn();  
    this.RadGrid1.MasterTableView.Columns.Add(boundColumn);  
 
    //Then set properties  
    boundColumn.DataField = "CustomerID";  
    boundColumn.HeaderText = "CustomerID";  
  }  


Thanks
Princy.
Tags
Grid
Asked by
anna
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
anna
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or