📜 ⬆️ ⬇️

Why GridView removes the entire design with an empty DataSource

I asked this question recently.
Took a reflector, opened the System.Web assembly

Here's what dug:

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 a GridView, overload CreateChildControls, copy the contents of this method from System.Web, of course, by changing this piece of code.
')
One of these days I will try to turn a similar piece.

Source: https://habr.com/ru/post/56125/


All Articles