在ASP.Net的GridView格式化日期时间在更新,而无需使用C# [英] Formatting DateTime in ASP.Net GridView while updating, without using c#

查看:375
本文介绍了在ASP.Net的GridView格式化日期时间在更新,而无需使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参考下面的code:

Refer the code below:

  <asp:TemplateField HeaderText="DOB" SortExpression="dob" >
                    <EditItemTemplate >
                        <asp:TextBox ID="TextBox3" Width="60px" runat="server" Text='<%# Bind("dob", "{0:d-M-yyyy}") %>'></asp:TextBox>

                        <asp:CalendarExtender ID="TextBox3_CalendarExtender"  runat="server" Enabled="True" Format="d-M-yyyy" TargetControlID="TextBox3">
                        </asp:CalendarExtender>

                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("dob", "{0:d-M-yyyy}") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

我在DB名为DOB一个DateTime列。我在D-M-YYY格式化它,而具有约束力。
一切正常,当用户直接从GridView控件更新他DOB除了完美的。

I've a DateTime column named "dob" in db. I've formatted it in "d-M-yyy" while binding. Everything works perfect except when user updates his DOB directly from GridView.

一直以来,我已经显示在文本框的日期在D-M-YYYY格式,而数据库服务器会将其作为MM-DD-YYYY格式,当用户要更新数据,那么问题就出现了。

Since, I've displayed the date in textbox in "d-M-yyyy" format, while db server treats it as "mm-dd-yyyy" format, then problem arises when user wants to update data.

顺便说一句,在服务器引发这样的:

By the way, the server raises this:

System.FormatException: String was not recognized as a valid DateTime.

code的更新:

Code for Update:

  UpdateCommand="update family_members_info set dob=@dob  where memberID=@memberID">              
            <UpdateParameters>                                
                <asp:Parameter Name="memberID" />                   
                <asp:Parameter Name="dob" Type="DateTime" />                    
            </UpdateParameters>

任何帮助将大大AP preciated。

Any help would be greatly appreciated.

推荐答案

在我的情况下帮助添加

<globalization culture="cs-CZ" uiCulture="cs-CZ" />

在web.config文件中的标记。

tag in the web.config file.

来源:的http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(v=vs.71).aspx

这篇关于在ASP.Net的GridView格式化日期时间在更新,而无需使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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