Reputation: 20906
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;
}
How can i create in the sam way empty row for repeater? Is it possible. I do not know how to add row and clear it...
Upvotes: 0
Views: 874
Reputation: 48583
Repeaters aren't guaranteed to contain rows and columns: they can have any internal structure (or no structure), so you can't do the same thing.
You're probably better off hiding the repeater and showing an entirely different control when your data source has no items, like an HTML literal.
Upvotes: 1