2010-10-04 33 views
5

正如在問題指出:使用CSS-Friendly Control Adapters的GridView - 使用CSS友好的控制適配器去除EmptyDataTemplate和EmptyDataText

解決的辦法之一是在this answer

指定禁用GridView控件組件addapters是否有解決方案,將允許繼續使用CSS-Friendly Control Adapters爲GridView和還利用EmptyDataTemplate功能?

+0

引人入勝,2014年仍然沒有解決...至少被接受的答案仍然有效。 – walther 2014-11-19 13:43:16

回答

3

如果你看一下源爲GridView中CSS友好適配器,在您的鏈接提供,你將看到如下(注意失蹤其他):

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

+1謝謝Nariman,這很好地解釋了爲什麼問題首先存在 – kristof 2010-10-05 09:12:57

1

以下內容添加到RenderContents在GridViewAdapter.cs前右/ //// 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風格,

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

} 
相關問題