Home All Groups Group Topic Archive Search About

Empty results hide GridView headers

Author
23 Oct 2006 7:38 AM
jean-pierre.riehl
Hi,

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
example).
Using Reflector, we can see that logic in CreateChildControls :
------
case 0: //number of row in DataView
  if ((this.EmptyDataTemplate != null) || (this.EmptyDataText.Length >
0))
  {
    this.CreateRow(-1, -1, DataControlRowType.EmptyDataRow,
DataControlRowState.Normal, dataBinding, null, fieldArray1,
collection4, null);
  }

  else
  {
    this.Controls.Clear();
  }
  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

Author
24 Oct 2006 3:06 PM
David Thielen
Use
http://blogs.claritycon.com/blogs/kevin_marshall/archive/2006/02/28/247.aspx

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




Show quoteHide quote
"jean-pierre.ri***@bewise.fr" wrote:

> Hi,
>
> 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
> example).
> Using Reflector, we can see that logic in CreateChildControls :
> ------
> case 0: //number of row in DataView
>   if ((this.EmptyDataTemplate != null) || (this.EmptyDataText.Length >
> 0))
>   {
>     this.CreateRow(-1, -1, DataControlRowType.EmptyDataRow,
> DataControlRowState.Normal, dataBinding, null, fieldArray1,
> collection4, null);
>   }
>
>   else
>   {
>     this.Controls.Clear();
>   }
>   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
>
>