一、EmptyDataTemplate,在这个模版中设置
<
EmptyDataTemplate
>
< table >
< tr >
< td ></ td >
< td ></ td >
< td ></ td >
</ tr >
< tr >
< td > --没有记录-- </ td >
</ tr >
</ table >
</ EmptyDataTemplate >
二、数据源为datatable
< table >
< tr >
< td ></ td >
< td ></ td >
< td ></ td >
</ tr >
< tr >
< td > --没有记录-- </ td >
</ tr >
</ table >
</ EmptyDataTemplate >
DataTable dt
=
userbll.GetList(
""
).Tables[
0
];
if (dt.Rows.Count == 0 )
{
dt.Rows.Add(dt.NewRow());
GridView1.DataSource = dt;
GridView1.DataBind();
int columnCount = dt.Columns.Count;
GridView1.Rows[0].Cells.Clear();
GridView1.Rows[0].Cells.Add(new TableCell());
GridView1.Rows[0].Cells[0].ColumnSpan = columnCount;
GridView1.Rows[0].Cells[0].Text = "---没有记录---";
GridView1.Rows[0].Cells[0].Style.Add("text-align", "center");
}
else
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
if (dt.Rows.Count == 0 )
{
dt.Rows.Add(dt.NewRow());
GridView1.DataSource = dt;
GridView1.DataBind();
int columnCount = dt.Columns.Count;
GridView1.Rows[0].Cells.Clear();
GridView1.Rows[0].Cells.Add(new TableCell());
GridView1.Rows[0].Cells[0].ColumnSpan = columnCount;
GridView1.Rows[0].Cells[0].Text = "---没有记录---";
GridView1.Rows[0].Cells[0].Style.Add("text-align", "center");
}
else
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}