我有 gridview 从 sql server 获取数据表。当数据表没有行时,我编写了一个函数来绑定来自单独源的gridview,该函数将新行添加到gridview 还合并所有列并显示错误消息“未找到结果”,但这不起作用所有列正在显示照原样。下面给出绑定空网格的函数
private void ShowNoResultFound(DataTable source, GridView gv, bool footerStatus)
{
source.Rows.Add(source.NewRow());
gv.DataSource = source;
gv.ShowFooter = footerStatus;
int columnsCount = gv.Columns.Count;
gv.DataBind();
gv.Rows[0].Cells.Clear();
gv.Rows[0].Cells.Add(new TableCell());
gv.Rows[0].Cells[0].ColumnSpan = columnsCount;
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;
gv.Rows[0].Cells[0].Text = "NO RESULT FOUND!";
}