1、无数据依然显示表头
// 参数:所要绑定的GridView 所要绑定的数据集
public void BindNoRecords(GridView gridView, DataSet ds)
{
if(ds.Tables[0].Rows.Count == 0)
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gridView.DataSource = ds;
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;
}
}
2、BoundField的格式化字符串
DataFormatString="{0:F}" 还要加上HtmlEncode="false"才会生效。
至于{0:F}格式请参照 String.Format格式说明
// 参数:所要绑定的GridView 所要绑定的数据集
public void BindNoRecords(GridView gridView, DataSet ds)
{
if(ds.Tables[0].Rows.Count == 0)
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gridView.DataSource = ds;
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;
}
}
2、BoundField的格式化字符串
DataFormatString="{0:F}" 还要加上HtmlEncode="false"才会生效。
至于{0:F}格式请参照 String.Format格式说明
回复Comments
{commenttime}{commentauthor}
{CommentUrl}
{commentcontent}