转个gridView没数据显示无任何记录的代码
// 参数:所要绑定的GridView 所要绑定的数据集 ,dataTable dt数据集中的数据表
public static void BindNoRecords(GridView gridView, DataTable dt)
{
if (dt.Rows.Count == 0)
{
dt.Rows.Add(dt.NewRow());
gridView.DataSource = dt;
gridView.DataBind();
int columnCount = gridView.Rows[0].Cells.Count;
gridView.Rows[0].Cells.Clear();
gridView.Rows[0].Cells.Add(new TableCell());
gridView.Rows[0].Cells[0].ColumnSpan = columnCount;
gridView.Rows[0].Cells[0].Text = "没有任何记录!";
gridView.RowStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
}
else
{
gridView.DataSource = dt;
gridView.DataBind();
}
}