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

Bind to GridView from data access layer

2 Answers 159 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sharon Eden
Top achievements
Rank 1
Sharon Eden asked on 22 Apr 2010, 05:40 PM
I have a data access layer component that returns typed dataset. It seems that simply setting the datasource property of the GridView doesn't work.

How do i bind a GridView to the returned dataset? do i have to define the grid's columns in advance and perform the binding?
by the way, I'm using the latest version evaluation copy.

Thanks in advance,

Sharon.

2 Answers, 1 is accepted

Sort by
0
Accepted
Julian Benkov
Telerik team
answered on 23 Apr 2010, 02:02 PM
Hello Sharon Eden,

If you bind the RadGridView DataSource property to a DataSet you must also set a DataMember property to some of DataTable located in DataSet.

DataSet binding:

DataSet dataSet = new DataSet();
DataTable table = new DataTable("Person");
table.Columns.Add("ID", typeof(int));
table.Columns.Add("ParentID", typeof(int));
table.Columns.Add("Name");
 
table.Rows.Add(1, null, "Andrew Fuller"); 
table.Rows.Add(3, 1, "Janet Leverling");  
table.Rows.Add(8, 3, "Laura Callahan");   
table.Rows.Add(9, 3, "Anne Dodsworth");   
table.Rows.Add(10, 4, "Monika Dion");     
table.Rows.Add(5, 1, "Steven Buchanan");
dataSet.Tables.Add(table);
 
this.radGridView1.DataMember = "Person";
this.radGridView1.DataSource = dataSet;

Direct binding:

this.radGridView1.DataSource = dataSet.Tables["Person"];

Greetings,
Julian Benkov
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.
0
Sharon Eden
Top achievements
Rank 1
answered on 26 Apr 2010, 11:09 AM
took me a while...

Anyway, your example was very helpful since it reminded me a small and silly thing that i forgot.

Thanks a lot for your help,

Sharon.
Tags
GridView
Asked by
Sharon Eden
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Sharon Eden
Top achievements
Rank 1
Share this question
or