How to persist a GridView header when control contains no row data

K

keithb

Is there some way to persist the header when a GridView control has no rows
containing data?

Thanks,

Keith
 
J

JudahReeves

You can subclass the GridView and add this to OnDataBound:


this.Controls.Add(new Table());
GridViewRow header = this.CreateRow(0, -1, DataControlRowType.Header,
DataControlRowState.Normal);
DataControlField[] fields = new DataControlField[this.Columns.Count];
this.InitializeRow(header, fields);
((Table)this.Controls[0]).Rows.Add(header);
 
J

JudahReeves

Noticed something:

this.Controls.Add(new Table());
GridViewRow header = this.CreateRow(0, -1, DataControlRowType.Header,
DataControlRowState.Normal);
DataControlField[] fields = new DataControlField[this.Columns.Count];

this.Columns.CopyTo(fields, 0);

this.InitializeRow(header, fields);
((Table)this.Controls[0]).Rows.Add(header);
 

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,434
Messages
2,571,690
Members
48,796
Latest member
Greg L.

Latest Threads

Top