【问题标题】:GridView - using CSS-Friendly Control Adapters removes EmptyDataTemplate and EmptyDataTextGridView - 使用 CSS 友好的控件适配器删除 EmptyDataTemplate 和 EmptyDataText
【发布时间】:2011-04-20 21:22:27
【问题描述】:

正如问题中指出的那样:

其中一种解决方案是禁用 this answer 中指定的 GridView 组件的适配器

有没有一种解决方案,可以让 GridView 继续使用 CSS-Friendly Control Adapters 并仍然利用 EmptyDataTemplate 功能?

【问题讨论】:

  • 令人着迷,2014 年,但仍未解决...至少接受的答案仍然有效。

标签: asp.net css gridview


【解决方案1】:

从源代码构建 cssfriendly,而不是使用下载链接。 目前最新的是http://cssfriendly.codeplex.com/SourceControl/changeset/changes/24242 当我使用该来源时, EmptyDataText 对我来说工作正常。

【讨论】:

    【解决方案2】:

    将以下内容添加到 GridViewAdapter.cs 中的 RenderContents,就在 ///// BODY //// 部分之前 ///////////// 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");
                }
            }
        }
    }   
    

    并在返回 className.Trim(); 之前将以下内容添加到 GetRowClass;

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

    最后,如果你想覆盖标准的 tfoot 样式,添加一个 CSS 部分

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

    【讨论】:

      【解决方案3】:

      如果您查看链接中提供的 GridView 的 CSS 友好适配器的源代码,您将看到以下内容(注意缺少的 else):

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

      基本上适配器没有提及 EmptyDataTemplateEmptyDataText - 这是一个简单的疏忽。修补它虽然很简单。你所要做的就是获取提供的源代码,看看原始的 GridView 是如何渲染它的,结合概念,并重建原始适配器:

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

      【讨论】:

      • +1 感谢 Nariman,这很好地解释了为什么首先存在问题
      猜你喜欢
      • 2011-02-27
      • 2016-06-14
      • 2010-10-13
      • 2010-09-21
      • 1970-01-01
      • 2010-10-13
      • 1970-01-01
      • 2011-01-23
      • 1970-01-01
      相关资源
      最近更新 更多