I have a data table and I know its got data when i debug it has two columns and 52 rows but I get the following error when binding to gridview:
The data source for GridView with id 'GridView1' did not have any properties or attributes from which to generate columns. Ensure that your data source has content.Below is my c# code
public DataTable RenderGrid()
{
dataTable = new DataTable(PlayerHsh.GetType().Name);
IDictionaryEnumerator enumerator = PlayerHsh.GetEnumerator();
//Add apporiate columns
dataTable.Columns.Add("Key", typeof(object));
dataTable.Columns.Add("Value", typeof(object));
while (enumerator.MoveNext())
{
dataTable.Rows.Add(enumerator.Key, enumerator.Value);
}
return dataTable;
}
CALLING CLASS .ASPX.CS PAGE C#
//Bind the team name and players to datagrid
rdg = new RenderDataGrid(mp.PlayerHsh, flp.TeamHsh);
rdg.RenderGrid();
GridView1.DataSource = rdg.dataTable;
GridView1.DataBind();
luke_bryant
Member
396 Points
361 Posts
Gridview Datasource
May 04, 2012 04:25 PM|LINK
Hi Programmers,
I have a data table and I know its got data when i debug it has two columns and 52 rows but I get the following error when binding to gridview: The data source for GridView with id 'GridView1' did not have any properties or attributes from which to generate columns. Ensure that your data source has content.Below is my c# code
public DataTable RenderGrid() { dataTable = new DataTable(PlayerHsh.GetType().Name); IDictionaryEnumerator enumerator = PlayerHsh.GetEnumerator(); //Add apporiate columns dataTable.Columns.Add("Key", typeof(object)); dataTable.Columns.Add("Value", typeof(object)); while (enumerator.MoveNext()) { dataTable.Rows.Add(enumerator.Key, enumerator.Value); } return dataTable; } CALLING CLASS .ASPX.CS PAGE C# //Bind the team name and players to datagrid rdg = new RenderDataGrid(mp.PlayerHsh, flp.TeamHsh); rdg.RenderGrid(); GridView1.DataSource = rdg.dataTable; GridView1.DataBind();luke_bryant
Member
396 Points
361 Posts
Re: Gridview Datasource
May 04, 2012 04:38 PM|LINK
Interestingly I add two more columns of type string and they appear on the page and the two coloumns in post dont
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Gridview Datasource
May 08, 2012 08:44 AM|LINK
Hi,
It should be like this directly:
GridView1.DataSource = rdg.RenderGrid();
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework