会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
一口遮天
沉默是一种倾听,倾听让人们增加智慧,喋喋不休的人,只会暴露自身的肤浅。
博客园
首页
新随笔
联系
订阅
管理
当DataSet为空时也显示GridView的表头
/**/
/**/
/**/
///
<summary>
///
当DataSet为空时也显示GridView的表头
///
</summary>
///
<param name="gridView">
所要绑定的GridView
</param>
///
<param name="ds">
所要绑定的数据集
</param>
///
<returns>
void
</returns>
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;
}
}
注:其他数据源 如 dataview datatable也类似的写法
if
(dv.Count
==
0
)
{
dv.Table.Rows.Add(dv.Table.NewRow());
this
.Gv_Storage.DataSource
=
dv;
this
.Gv_Storage.DataBind();
int
count
=
this
.Gv_Storage.Rows[
0
].Cells.Count;
Gv_Storage.Rows[
0
].Cells.Clear();
Gv_Storage.Rows[
0
].Cells.Add(
new
TableCell());
Gv_Storage.Rows[
0
].Cells[
0
].ColumnSpan
=
count;
Gv_Storage.Rows[
0
].Cells[
0
].Text
=
"
没有记录
"
;
Gv_Storage.RowStyle.HorizontalAlign
=
System.Web.UI.WebControls.HorizontalAlign.Center;
}
else
{
this
.Gv_Storage.DataSource
=
dv;
this
.Gv_Storage.DataBind();
}
我的淘宝店:
http://hamby.taobao.com
posted @
2008-04-26 16:52
hambywu
阅读(
1114
) 评论(
1
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告