当没有数据时,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.
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.
相关文章推荐
- 当没有数据时,girdview不显示任何东西,但是需要显示列名.
- jqgrid传入的json数据,赋值了但是没有在表格上显示
- VB.Net机房收费系统(三层)——用datagirdview 控件显示数据库数据
- GridView模版列嵌套GirdView显示主从表数据
- tableview 没有数据显示的时候,插入无数据的view
- mater上面有数据 slave不同步 但是没有任何报错信息
- 关于Repeater、GirdView修改显示的数据
- GridView模版列嵌套GirdView显示主从表数据
- SwipeRefreshLayout配合RecyclerView实现下拉刷新和上拉加载更多以及没有数据的显示
- 动态地往datagirdview中添加数据,当所添加的数据超过datagridview的显示范围后,滚动条就无法显示,程序出现假死状态,(scrollbars=both)
- GridView模版列嵌套GirdView显示主从表数据
- (转)GridView模版列嵌套GirdView显示主从表数据
- 如果程序代码没有任何问题,但是工程还是显示错误,首先调整3步
- SSH整合出现org.hibernate.LazyInitializationException: could not initialize proxy - no Session或者前台没有显示任何数据
- SwipeRefreshLayout配合RecyclerView实现下拉刷新和上拉加载更多以及没有数据的显示
- curl爬数据,返回页面结果,如果没有任何显示,该怎么办?
- DataGrid没有数据但是还是显示标头
- django程序没有问题,保存远地测试数据库,save没问题,控制台也显示update成功,但是在数据库检索数据没有存进去
- C#后台制作之数据库(Access数据库+datagirdview控件显示+串口数据存储)
- [导入]GridView模版列嵌套GirdView显示主从表数据