Paging in Dynamic created Datagrid

G

Guest

Hi,

I have dynamically created a datagrid by:

1. created a number of columns from reading a column difinition so I can
dynamically create the columns I want to display.

2. bind to a datasource which has data more than the above columns

It populates the dg properly, but the OnPageIndexedChange will not fire as
long as I make dg's AutoGenerateColumns to false. I have to do it otherwise
it will ignore my dynamically created limited number of columns I want to
display. If I set to true it will display the columns I want but paging
won't work.

I have a test code if you need see it to help me out. Thanks!
 
G

Guest

I got it! Re-create the columns upon every postback prior to Page_Load().

override protected void OnInit(EventArgs e)
{
CreateDg(); // <<<<<<<< Re-create the DataGrid before Page_Load
InitializeComponent();
base.OnInit(e);
}
private void CreateDg()
{
....
DataGrid1.AutoGenerateColumns = false;
DataGrid1.PageIndexChanged += new DataGridPageChangedEventHandler(
DataGrid1_PageIndexChanged);
....
// Add datagrid column definition here...
);


-- Steve
 

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

Forum statistics

Threads
474,265
Messages
2,571,069
Members
48,771
Latest member
ElysaD

Latest Threads

Top