如何更改 GridView 中 BoundField 的方向
抱歉,如果我的问题看起来很简单。
现在,在我的 GridView 的 BoundField 中,一些数据显示为“12/11/1381”,我想显示为“1381/11/12”(相反方向)。
我知道我可以通过 TemplateField 中的 rtl 和 ltr 更改方向。但由于某种原因,我无法将边界字段转换为模板字段。
我查看了所有 BoundField 属性以改变方向,但我什么也没发现。
我认为应该在 GridView 的 RowDataBound 事件中完成,但我不知道如何!?
您对本案有何看法?
提前致谢。
Sorry if my question seems to simple .
Right now in the BoundField of my GridView some data display like "12/11/1381" that i wanna display like "1381/11/12" (opposite direction) .
I know i could change the direction via rtl and ltr in TemplateField. But because of some reason i can't convert my boundfield to templatefield.
I looked through all BoundField properties in order to change direction , but i found nothing.
I think that should be done in RowDataBound event of GridView , But i don't know how !?
What do you think at this case ?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,由于它是作为字符串输入的日期,因此至少有两种方法可以做到这一点。
方法1
将字符串数据绑定为
Date
对象而不是String
。由于我现在不知道原始日期的确切日期格式,dd/MM/yyyy 或 MM/dd/yyyy,您必须自己弄清楚。如果您可以做到这一点,只需将其添加到“BoundField”元素:
或
方法 2
操作 ROwDataBound oevent 中的文本。我在这里做了一个粗略的,可以完善一下。您可能应该将它们作为
Date
对象进行操作。在 ASPX 中:
代码隐藏:
Ok, since it's a date which was input as string, there are at least 2 ways you can do it.
Method 1
Databind the string as a
Date
object instead ofString
. As I do not now the exact date format of the original date, dd/MM/yyyy or MM/dd/yyyy, you'll have to figure it out yourself.If you can do that, just add this to the "BoundField" element:
or
Method 2
Manipulate the text in ROwDataBound oevent. I've done a crude one here which can be polished up. You should probably manipulate them as
Date
objects.In the ASPX:
CodeBehind:
首先确保您已设置
HtmlEncode="False"
尝试将其添加到 BoundField 标记 -
这是一篇应该对您有所帮助的好文章 - 如何在 GridView 中设置日期格式
First make sure you have set
HtmlEncode="False"
try adding this to the BoundField tag -
here is a good article that should help you - How To Set a Date Format In GridView