如何处理GridView数据绑定时数据源为空时显示表头和quot的问题?
DataTable dt_Test = new DataTable();
dt_Test = obj.GetList();
if(dt_Test.Rows.Count == 0)
{
dt_Test.Rows.Add(dt.NewRow());
gv_Test.DataSource = dt_Test;
gv_Test.DataBind();
int columnCount = dt_Test.Rows[0].Cells.Count;
gv_Test.Rows[0].Cells.Clear();
gv_Test.Rows[0].Cells.Add(new TableCell());
gv_Test.Rows[0].Cells[0].ColumnSpan = columnCount;
gv_Test.Rows[0].Cells[0].Text = "没有记录";
gv_Test.Rows[0].Cells[0].Style.Add("text-align","center");
}
else
{
gv_Test.DataSource = dt_Test;
gv_Test.DataBind();
}
本文地址:http://www.45fan.com/a/question/67185.html