动态将格式字符串应用于gridview单元 [英] Apply format string to gridview cell dynamically

查看:69
本文介绍了动态将格式字符串应用于gridview单元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将sharepoint中文档库的修改"列绑定到标签,但是修改后的列包含日期和时间,我只想绑定日期,否则我创建了一个名为date的列,该列仅接受且不接受日期作为输入但是当我将其绑定到标签上时,其显示时间也是最后一次动态绑定.
我试过了


i am binding "modified" column of document library in sharepoint to a label,but modified column contains date as well as time ,i just want to bind date alternatively i created a column called date which take and aloowed only date as input but when i bind it to a label its showing time also,last soln is to bind dynamically.
i tried


e.Row.Cell[column number]Convert.ToDateTime(e.Row.Cells[column number].Text).ToString("dd/MM/yyyy"); 

,但是它给了转换错误
有人可以帮忙吗?

but its giving error of conversion
can anyone help?

推荐答案

当使用网格视图单元格绑定包含日期和时间的列并且您只需要显示日期时,有两种可能的解决方法
1)使用绑定的字段并设置DateFormatString ="{0:d}"
2)如果您使用的是Templete菲尔德,则可以在绑定时通过使用Text =<%#string.Format("{0:d}",Eval("Column Name"))%>直接将日期和时间转换为日期;>
when binding a column cointaining a date and time with a grid view cell and u just need to show date there are two possible solutions
1)using bound feild and setting DateFormatString="{0: d}"
2)If you are using templete feild the you can directly convert date and time into date while binding by using Text=<%#string.Format("{0: d}",Eval("Column Name"))%>>


这篇关于动态将格式字符串应用于gridview单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆