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

[Solved] Programatically create RadGrid

1 Answer 266 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ashish
Top achievements
Rank 1
Ashish asked on 26 Jun 2009, 03:08 PM

RadGrid

 

r = new RadGrid();

 

 

r.MasterTableView.DataKeyNames =

new string[] { "DepartmentID" };

 

 

 

r.Skin =

"Default";

 

 

 

r.Width =

Unit.Percentage(100);

 

 

 

r.PageSize = 5;

r.AllowPaging =

true;

 

 

 

r.AutoGenerateColumns =

 

 

false;

 

r.MasterTableView.PageSize = 15;

 

 

//Add columns

 

 

 

GridBoundColumn boundColumn;

 

boundColumn =

 

new GridBoundColumn();

 

boundColumn.DataField =

 

"DepartmentID";

 

boundColumn.HeaderText =

 

"DepartmentID";

 

r.MasterTableView.Columns.Add(boundColumn);

boundColumn =

 

new GridBoundColumn();

 

boundColumn.DataField =

 

"Budget";

 

boundColumn.HeaderText =

 

"Budget";

 

r.MasterTableView.Columns.Add(boundColumn);

 

 

 

 

 

//Detail table - Orders (II in hierarchy level)

 

 

 

GridTableView tableViewOrders = new GridTableView(r);

 

 

 

//tableViewOrders.DataSourceID = "AccessDataSource2";

 

 

tableViewOrders.DataKeyNames =

new string[] { "CourseID" };

 

 

 

GridRelationFields relationFields = new GridRelationFields();

 

relationFields.MasterKeyField =

 

"DepartmentID";

 

relationFields.DetailKeyField =

 

"DepartmentID";

 

tableViewOrders.ParentTableRelation.Add(relationFields);

RadGrid1.MasterTableView.DetailTables.Add(tableViewOrders);

 

 

//Add columns

 

 

boundColumn =

new GridBoundColumn();

 

boundColumn.DataField =

 

"CourseID";

 

boundColumn.HeaderText =

 

"CourseID";

 

tableViewOrders.Columns.Add(boundColumn);

boundColumn =

 

new GridBoundColumn();

 

boundColumn.DataField =

 

"Title";

 

boundColumn.HeaderText =

 

"Title";

 

tableViewOrders.Columns.Add(boundColumn);

r.AllowMultiRowSelection =

 

true;

 

r.MasterTableView.DetailTables.Add(tableViewOrders);

r.DetailTableDataBind +=

 

new GridDetailTableDataBindEventHandler(r_DetailTableDataBind);

 

r.NeedDataSource +=

 

new GridNeedDataSourceEventHandler(r_NeedDataSource);

 

r.ID =

 

"RockOn";

 

 

 

this.PlaceHolder1.Controls.Add(r);

its the same code posted on Site Examples..


it loads ok but when i try to expand the grid Row ... i get an error--


Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.


on page load i m binding the DataSets to the Grid

 

 

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Jun 2009, 06:32 AM
Hi Ashish,

Try wrapping your code in the if (!IsPostBack) condition and see whether it helps.

CS:
 
protected void Page_Load(object sender, EventArgs e)    
{    
     if (!IsPostBack)   
     {  
          // Code to create radgrid 
     }           

Go through the following link to know more about creating radgrid programmatically.
Programmatic creation

Shinu.
Tags
Grid
Asked by
Ashish
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or