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

前端 未结 3 628
傲寒
傲寒 2021-01-19 00:38

As pointed out in the question:

  • EmptyDataTemplate and EmptyDataText not working in GridView

    using CSS-Friendly Control Adapters removes the data that

3条回答
  •  [愿得一人]
    2021-01-19 01:17

    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
    {
    
    }
    

提交回复
热议问题