2010-09-16 26 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