您的位置:首页 > 其它

当没有数据时,girdview不显示任何东西,但是需要显示列名.

2007-06-19 13:40 561 查看
1 自己写个dt里面新建一个datarow,函数如下:

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:girdview里面有个EmpyDataTempLate 这个模板列就是当你的数据源为空时显示的,你自己可以在里面拉一个table 写上你的表头.

3: 用其他的控件:如repeater.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐