GridView – using CSS-Friendly Control Adapters removes EmptyDataTemplate and EmptyDataText

As pointed out in the question:

One of the solutions is to disable the addapters for GridView components as specified in this answer

Is there a solution, that would allow to keep the use of CSS-Friendly Control Adapters for GridView and still take advantage of EmptyDataTemplate functionality?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Build cssfriendly from source instead of using the download link.
Currently the latest is http://cssfriendly.codeplex.com/SourceControl/changeset/changes/24242
and EmptyDataText is working fine for me when I use that source.

Method 2

If you look at the source for the CSS-Friendly adapter for GridView, provided in your link, you will see the following (note the missing else):

private void WriteRows(HtmlTextWriter writer, GridView gridView, GridViewRowCollection rows, string tableSection)
{
    if (rows.Count > 0)
    {

Basically the adapter makes no mention of EmptyDataTemplate or EmptyDataText – it’s a simple oversight. Patching it is straightforward though. All you have to do is take the source provided, look at how the original GridView renders it, combine the concepts, and rebuild the original adapter:

case DataControlRowType.EmptyDataRow:
                if (this._emptyDataTemplate == null)
                {
                    container = new TableCell();
                    string emptyDataText = this.EmptyDataText;
                    if (emptyDataText.Length > 0)
                    {
                        container.Text = emptyDataText;
                    }
                    break;
                }
                container = new TableCell();
                template = this._emptyDataTemplate;
                break;
        }
        if (container != null)
        {
            if (columnSpan > 1)
            {
                container.ColumnSpan = columnSpan;
            }
            if (template != null)
            {
                template.InstantiateIn(container);
            }
            row.Cells.Add(container);
        }

Method 3

Add the following to RenderContents in GridViewAdapter.cs right before the ///// BODY //// section
/////////////// EmptyDataTemplate ///////////////////////

if (gridView.Rows.Count == 0) {
    //Control[0].Control[0] s/b the EmptyDataTemplate.
    if (gridView.HasControls()) {
        if (gridView.Controls[0].HasControls()) {
            if (gridView.Controls[0].Controls[0] is GridViewRow) {
                rows.Clear();
                rows.Add(gridView.Controls[0].Controls[0]);
                gvrc = new GridViewRowCollection(rows);
                WriteRows(writer, gridView, gvrc, "tfoot");
            }
        }
    }
}

And add the following to GetRowClass right before return className.Trim();

//// EmptyDataTemplate 
if ((row.RowType & DataControlRowType.EmptyDataRow) == DataControlRowType.EmptyDataRow) {
className += " AspNet-GridView-Empty ";
}

Finally, if you want to override the standard tfoot style, add a CSS section

.AspNet-GridView table tfoot tr.AspNet-GridView-Empty td
{

}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x