Dynamic columns in DataGrid, Paging/Sorting and Data Caching

K

Kostia

Hi,
I have a DataGrid that has no columns and that is populated with
columns based on data obtained from DB during PageLoad in the
following way:

//reset adapter and datatable mapping
oleDbDataAdapter.TableMappings.Clear();
System.Data.Common.DataTableMapping tableMap =
oleDbDataAdapter.TableMappings.Add("Table", "SummaryData");
// create each column in the table
BoundColumn col = new BoundColumn();
col.HeaderText=columnsInfo["displayName"].ToString();
col.DataField=columnsInfo["columnName"].ToString().;
SumOutTable.Columns.Add(col);
tableMap.ColumnMappings.Add(new
System.Data.Common.DataColumnMapping(colstr, colstr));
oleDbDataAdapter.Fill(dsSummaryData);
Cache["SummaryResults"]=dsSummaryData;
SumOutTable.DataSource = dsSummaryData;
SumOutTable.DataBind();

onpageindexchanged is called when page is changed and here it is:
protected virtual void OnPageIndexChanged(Object sender,
DataGridPageChangedEventArgs
e)
{
// Set CurrentPageIndex to the page the user clicked.
SumOutTable.CurrentPageIndex = e.NewPageIndex;
// Rebind the data to refresh the DataGrid control.
SumOutTable.DataSource = (DataSet)Cache["SummaryResults"];
SumOutTable.DataBind();
}

It seems that Data is there and there are no exceptions however the
page of the datagrid contains no data and no columns?
Does it have anything to do with columns being added dynamically?
How do I solve this problem? Anything that could be said about sorting
and possible problems I will run into there?
Kostia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top