//dt為DataTable判斷是否為0筆資料
if (dt.Rows.Count == 0)
{
dt.Columns[1].AllowDBNull = true;
dt.Rows.Add(dt.NewRow());
GridView1.DataSource = dt;
GridView1.DataBind();
int columnCount = GridView1.Rows[0].Cells.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.RowStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
}
else
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
參考至:http://blog.finalevil.com/2008/11/aspnetgridview01.html
沒有留言:
張貼留言