空行Repeater动态

时间:2010-09-16 20:28:33

标签: c#

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 个答案:

答案 0 :(得分:1)

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

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