Empty results hide GridView headers




With ASP.NET 2.0 (I don't remember about a such problem in 1.1),
GridView control has a strange rendering rule. When dataview is empty
(no data or data fitered), GridView control ONLY renders
<EmptyDataTemplate> (or EmptyDataText property). It is impossible to
render columns headers (and filter controls created with it for
Using Reflector, we can see that logic in CreateChildControls :
case 0: //number of row in DataView
if ((this.EmptyDataTemplate != null) || (this.EmptyDataText.Length >
this.CreateRow(-1, -1, DataControlRowType.EmptyDataRow,
DataControlRowState.Normal, dataBinding, null, fieldArray1,
collection4, null);

this._storedDataValid = false;
this._firstDataRow = null;
return 0;
Nothing is rendered except an "empty" row.

I found some workarounds on Internet (many guys have the same problem)
but none of them satisfy me. They are :
-Create an empty data row in DataSource (possible mistake between
real data and fake data in all layers)
-Manually render Headers on RowCreated event (use of protected
CreateRow method or duplicate some Framework code)

My questions are :
-Is MS aware about that "problem" ?
-Which workaround is recommanded by MS ?
-Will it be fixed in next Service Pack ? (and when)

Jean-Pierre Riehl
Bewise (http://www.bewise.fr)
Ingénieur Consultant


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