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

前端 未结 3 648
傲寒
傲寒 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条回答
  •  Happy的楠姐
    2021-01-19 00:51

    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);
            }
    

提交回复
热议问题