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

Dynamic DataTable for RadGrid

1 Answer 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
suresh kumar
Top achievements
Rank 1
suresh kumar asked on 13 May 2010, 11:02 AM

how do i create a Dynamic DataTable for RadGrid.

I just follow the same procedure for GridView

DataTable myDataTable = new DataTable();

 

 

 

DataColumn myDataColumn;

 

myDataColumn =

 

new DataColumn();

 

myDataColumn.DataType =

 

Type.GetType("System.String");

 

myDataColumn.ColumnName =

 

"ID";

 

myDataTable.Columns.Add(myDataColumn);

myDataColumn =

 

new DataColumn();

 

myDataColumn.DataType =

 

Type.GetType("System.String");

 

myDataColumn.ColumnName =

 

"TestName";

 

myDataTable.Columns.Add(myDataColumn);

myDataColumn =

 

new DataColumn();

 

myDataColumn.DataType =

 

Type.GetType("System.String");

 

myDataColumn.ColumnName =

 

"ReportResults";

 

myDataTable.Columns.Add(myDataColumn);

myDataColumn =

 

new DataColumn();

 

myDataColumn.DataType =

 

Type.GetType("System.String");

 

myDataColumn.ColumnName =

 

"CommunicationType";

 

myDataTable.Columns.Add(myDataColumn);

 

 

//add test row

 

 

 

 

 

 

 

DataRow drow = myDataTable.NewRow();

 

drow[

 

"ID"] = Guid.NewGuid().ToString();

 

drow[

 

"TestName"] = "TestName1";

 

drow[

 

"ReportResults"] = "ReportName1";

 

drow[

 

"CommunicationType"] = "CommunicationType1";

 

 

 

//Add the row to the datatable.

 

 

 

 

 

myDataTable.Rows.Add(drow);

this datatable is working fine for GridView.
But when i binding for RADGRID, it showing some error like
"

Name is neither a DataColumn nor a DataRelation for table .

"
Any help will be highly appriceated.

Regards,
Suresh Kumar Udatha.

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 13 May 2010, 11:13 AM
Hi suresh,

The error is coming from an incorrect declaration for your RadGrid (or programmatic creation). Have you set "Name" as the DataKeyValue for the grid? Could you paste your complete aspx and code-behind (do use the code formatter tool of the ticket editor to make your code readable).

All the best,
Tsvetoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
suresh kumar
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or