C# Convert DataTable to List and Add to GridView

I'm following code in this example -> http://dotnetawesome.blogspot.com/2014/01/how-to-group-columns-in-gridview-header-row-aspnet-programmer-friendly-way.html

On the website they have the below piece of code.
private void PopulateData()
2.            {
3.                using (MyDatabaseEntities dc = new MyDatabaseEntities())
4.                {
5.                    GridView1.DataSource = dc.SampleDatas.ToList();
6.                    GridView1.DataBind();
7.                }
8.                // Add Group Header
9.                SetGroupHeader();
10.            }

Open in new window


I am getting my data from a stored procedure and it is in a dataset.  How do I convert it to a List?  Do I have to convert it to a list to get the same result?

This is the video https://www.youtube.com/watch?v=LkFssh96VCE

Thank You
LVL 2
CipherISAsked:
Who is Participating?
 
Fernando SotoRetiredCommented:
Try something like this, where DataSet_Instance_Name is your DataSet object and XXX is the table name as a string or the index in the collection of Tables.
GridView1.DataSource = DataSet_Instance_Name.Table[XXX]; 
GridView1.DataBind();

Open in new window

0
 
Lokesh B RDeveloperCommented:
Hi,

You can bind the DataTable as follows.

GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();

Imagine that your DataSet name is ds.
0
 
CipherISAuthor Commented:
Gridview.DataSource = dt;

I usually set it like that.  Thought I needed to convert it to a list for the other code.
0
 
Lokesh B RDeveloperCommented:
Hi,

There is no property called Table on DataSet.

It is DataSet.Tables

https://msdn.microsoft.com/en-us/library/system.data.dataset.tables%28v=vs.110%29.aspx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.