我有gridview从sql server获取数据表。当数据表没有行时,我编写了一个函数来绑定来自单独源的gridview,它将一个新行添加到gridview,同时合并所有列并显示错误消息" No Result found"但这不起作用所有列都显示为原样。绑定空网格的功能如下所示
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!";
}
答案 0 :(得分:1)
设置EmptyDataText =“找不到结果!!!” Grdi View的属性