2010-09-16 27 views
0
public static void ShowNoResultFoundGridWiew<T>(List<T> source, GridView gv, string text) where T : new() 
     { 
      if (source == null) 
       return; 

      source.Add(new T()); 
      gv.DataSource = source; 
      gv.DataBind(); 

      // Get the total number of columns in the GridView to know what the Column Span should be 
      int columnsCount = gv.Columns.Count; 
      gv.Rows[0].Cells.Clear(); // clear all the cells in the row 
      gv.Rows[0].Cells.Add(new TableCell()); //add a new blank cell 
      gv.Rows[0].Cells[0].ColumnSpan = columnsCount; //set the column span to the new added cell 

      // You can set the styles here 
      ////gv.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center; 
      ////gv.Rows[0].Cells[0].ForeColor = System.Drawing.Color.Red; 
      ////gv.Rows[0].Cells[0].Font.Bold = true; 

      // Or you can pass a css class name 
      //gv.Rows[0].Cells[0].CssClass = "EmptyDataRowStyle"; 

      gv.Rows[0].Cells[0].Text = text; 
     } 

我该如何创建山姆方式空行中继器?可能吗。我不知道如何添加行并清除它...空行中继器动态

回答

1

中继器不能保证包含行和列:它们可以有任何内部结构(或没有结构),所以你不能做同样的事情。

当您的数据源没有任何项目(如HTML文字)时,您可能最好隐藏中继器并显示完全不同的控件。

+0

嗨,thx对于如此快速的回答。我将使用标签并显示文字... – senzacionale 2010-09-16 20:40:43