Why GridView removes all design when DataSource is empty
I asked this question recently.
I took the reflector, opened the System.Web assembly.
Here's what I found:
The CreateChildControls method of the GridView:
The workaround is to inherit from GridView, overload CreateChildControls, copy the contents of this method from System.Web, naturally changing this piece of code.
One of these days I’ll try to crank such a thing.
I took the reflector, opened the System.Web assembly.
Here's what I found:
The CreateChildControls method of the GridView:
switch (count)
{
case -1:
// удалено
case 0:
if ((this.EmptyDataTemplate != null) || (this.EmptyDataText.Length > 0))
{
this.CreateRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal, dataBinding, null, array, rows, null);
}
else
{
// Вот она пакость...
this.Controls.Clear();
}
this._storedDataValid = false;
this._firstDataRow = null;
return 0;
}
* This source code was highlighted with Source Code Highlighter.
The workaround is to inherit from GridView, overload CreateChildControls, copy the contents of this method from System.Web, naturally changing this piece of code.
One of these days I’ll try to crank such a thing.