会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
秦岭过客
博客园
首页
订阅
管理
GridView控件在没有数据时显示表头和没有数据
GridView控件在没有数据时显示表头和没有数据,这里介绍两中方法,一、EmptyDataTemplat 二、DataTable,这两中方法的复用性都不强,每次都要写,希望那位高手能给个“偷懒”的办法。
一、EmptyDataTemplate,在这个模版中设置
<
EmptyDataTemplate
>
<
table
>
<
tr
>
<
td
></
td
>
<
td
></
td
>
<
td
></
td
>
</
tr
>
<
tr
>
<
td
>
--没有记录--
</
td
>
</
tr
>
</
table
>
</
EmptyDataTemplate
>
二、数据源为datatable
DataTable dt
=
userbll.GetList(
""
).Tables[
0
];
if
(dt.Rows.Count
==
0
)
{
dt.Rows.Add(dt.NewRow());
GridView1.DataSource
=
dt;
GridView1.DataBind();
int
columnCount
=
dt.Columns.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.Rows[
0
].Cells[
0
].Style.Add(
"
text-align
"
,
"
center
"
);
}
else
{
GridView1.DataSource
=
dt;
GridView1.DataBind();
}
}
posted on
2007-06-06 09:47
秦岭过客
阅读(
1075
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部