在Codebehind内动态设置显示内容的DataFormatString
2004-11-16 13:04
525 查看
在DataGrid内控制单元格显示内容的格式,如时间格式的时候
如果AutoGenerateColumns=false
那么绑定列中设置 DataFormatString="{0:dd/mm/yyyy}" 就可以做到了
可是AutoGenerateColumns=true的时候,就不好办了
一个办法,可以在sql语句中使用convert或者cast函数转换一下。
我们正在做的一个项目中
有个动态查询功能,是根据用户选择的条件、需显示的字段来动态生成Sql语句(破坏了三层结构,不知道其他朋友如何做?)来查询的。
如果用Sql的函数将非常麻烦,我采用了如下方法,在后台绑定数据的时候设置内容格式。
示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="gb2312" lang="gb2312">
<head>
<title> AutoGenerateColumns为true时,在Codebehind内设置内容的DataFormatString </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="title" content="" />
<meta name="author" content="活靶子,Huobazi,www.AspxBoy.com" />
<meta name="subject" content="" />
<meta name="language" content="gb2312" />
<meta name="keywords" content="" />
<meta name="Copyright" content="www.AspxBoy.com" />
<meta name="robots" content="all" />
</script>
</head>
<body>
<form runat="server">
<ASP:DataGrid id="dg" runat="server"
HeaderStyle-BackColor="#aaaadd"
AutoGenerateColumns="true"
OnItemDataBound="ItemDataBound"
Width="100%"
>
</asp:DataGrid>
</form>
</body>
</html>
http://www.aspxboy.com/Files/71/66/285.Aspx
如果AutoGenerateColumns=false
那么绑定列中设置 DataFormatString="{0:dd/mm/yyyy}" 就可以做到了
可是AutoGenerateColumns=true的时候,就不好办了
一个办法,可以在sql语句中使用convert或者cast函数转换一下。
我们正在做的一个项目中
有个动态查询功能,是根据用户选择的条件、需显示的字段来动态生成Sql语句(破坏了三层结构,不知道其他朋友如何做?)来查询的。
如果用Sql的函数将非常麻烦,我采用了如下方法,在后台绑定数据的时候设置内容格式。
示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="gb2312" lang="gb2312">
<head>
<title> AutoGenerateColumns为true时,在Codebehind内设置内容的DataFormatString </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="title" content="" />
<meta name="author" content="活靶子,Huobazi,www.AspxBoy.com" />
<meta name="subject" content="" />
<meta name="language" content="gb2312" />
<meta name="keywords" content="" />
<meta name="Copyright" content="www.AspxBoy.com" />
<meta name="robots" content="all" />
</script>
</head>
<body>
<form runat="server">
<ASP:DataGrid id="dg" runat="server"
HeaderStyle-BackColor="#aaaadd"
AutoGenerateColumns="true"
OnItemDataBound="ItemDataBound"
Width="100%"
>
</asp:DataGrid>
</form>
</body>
</html>
http://www.aspxboy.com/Files/71/66/285.Aspx
相关文章推荐
- 感受DataGrid给数据操作带来的便利(3)
- 感受DataGrid给数据操作带来的便利(2)
- 感受DataGrid给数据操作带来的便利(1)
- 神影无踪-廖添丁FlashGame
- 消息队列(Message Queue)简介及其使用
- XMLHTTP 对象及其方法简介
- 关于分页类的改进....
- 图片或文字或图文混合连续滚动
- 梦难留 - 郭富城
- 异常处理规范
- MFC对话框程序中添加工具栏及工具栏上的Button响应UPDATE_COMMAND_UI消息
- SAP B1的安装包真烂!
- 一个人就是一群疯子[a man consists of a gang of bedlamites]
- text1
- 一些感兴趣的文章的链接(看后删除)
- 饭桶札记
- 摘抄---关于activeSync via usb device的资料
- 我申请了自己的BLOG
- 揭开SVCHOST.exe进程之谜(转)
- 测试能用的blog界面修改方法