ObjectDataSource DateTime isuue with en-gb culture

Discussion in 'ASP .Net Web Controls' started by Anne Catterick, Dec 13, 2005.

  1. Hi,

    I have an british ASP.Net 2.0 application which is doing what (should) be
    very simple. But I am having issues.

    On my page I have a GridView as follows (some tags excluded for easy reading):

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    DataSourceID="ObjectDataSource1" DataKeyNames="Id"
    OnRowUpdated="GridView1_RowUpdated">
    <Columns>
    <asp:BoundField DataField="CreateDate" HeaderText="Create Date"
    SortExpression="CreateDate"
    DataFormatString="{0:d}" ApplyFormatInEditMode="True"
    ReadOnly="True" HtmlEncode="False">
    <HeaderStyle Wrap="False" />
    </asp:BoundField>
    <asp:CommandField ButtonType="Image"
    CancelImageUrl="~/images/manager/false.gif"
    EditImageUrl="~/images/manager/edit.gif"
    ShowEditButton="True" UpdateImageUrl="~/images/manager/true.gif" />
    </Columns>
    </asp:GridView>

    This is bound to an ObjectDataSource defined as follows:

    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
    SelectMethod="GetCampaigns"
    TypeName="B3.Mailer.BusinessEntities.Campaign"
    DataObjectTypeName="B3.Mailer.BusinessEntities.Campaign"
    InsertMethod="Insert" UpdateMethod="Update">
    <SelectParameters>
    <asp:SessionParameter Name="clientId" SessionField="ClientId"
    Type="Int32" />
    </SelectParameters>
    </asp:ObjectDataSource>

    The update method is defined as:

    public static void Update(Campaign campaign)
    {
    }

    However, when I edit a row in the GridView and press the update button I get
    the following error:

    [InvalidOperationException: Cannot convert value of parameter 'CreateDate'
    from 'System.String' to 'System.DateTime']
    System.Web.UI.WebControls.ObjectDataSourceView.ConvertType(Object value,
    Type type, String paramName) +485
    System.Web.UI.WebControls.ObjectDataSourceView.BuildObjectValue(Object
    value, Type destinationType, String paramName) +217
    System.Web.UI.WebControls.ObjectDataSourceView.BuildDataObject(Type
    dataObjectType, IDictionary inputParameters) +548
    System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary
    keys, IDictionary values, IDictionary oldValues) +1520
    System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values,
    IDictionary oldValues, DataSourceViewOperationCallback callback) +179
    System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32
    rowIndex, Boolean causesValidation) +1137
    System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
    causesValidation, String validationGroup) +835
    System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs
    e) +162
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
    System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source,
    EventArgs e) +118
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
    System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +106
    System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String
    eventArgument) +200

    System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    sourceControl, String eventArgument) +32
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
    System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3840

    This appears to be caused by the date being in UK format (dd/mm/yyyy - which
    is correct for this application) as dates which could also be in US format
    (i.e. 12/12/2005) do not throw this error.

    Both my browser and development machine are set to en-gb but there is no
    Culture attribute set on the @Page tags on the page.

    Is this a bug in the ObjectDataSource not conforming to globalization or am
    I missing somthing?

    Any help you can give will be much appreciated. Thanks in advance for your
    help.

    Regards,

    Anne.
     
    Anne Catterick, Dec 13, 2005
    #1
    1. Advertising

  2. Anne Catterick

    Brock Allen Guest

    Perhaps this is your problem:

    http://wintellect.com/WEBLOGS/wintellect/archive/2005/11/17/2363.aspx

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen

    > Hi,
    >
    > I have an british ASP.Net 2.0 application which is doing what (should)
    > be very simple. But I am having issues.
    >
    > On my page I have a GridView as follows (some tags excluded for easy
    > reading):
    >
    > <asp:GridView ID="GridView1" runat="server"
    > AutoGenerateColumns="False"
    > DataSourceID="ObjectDataSource1" DataKeyNames="Id"
    > OnRowUpdated="GridView1_RowUpdated">
    > <Columns>
    > <asp:BoundField DataField="CreateDate" HeaderText="Create
    > Date"
    > SortExpression="CreateDate"
    > DataFormatString="{0:d}" ApplyFormatInEditMode="True"
    > ReadOnly="True" HtmlEncode="False">
    > <HeaderStyle Wrap="False" />
    > </asp:BoundField>
    > <asp:CommandField ButtonType="Image"
    > CancelImageUrl="~/images/manager/false.gif"
    > EditImageUrl="~/images/manager/edit.gif"
    > ShowEditButton="True" UpdateImageUrl="~/images/manager/true.gif" />
    > </Columns>
    > </asp:GridView>
    > This is bound to an ObjectDataSource defined as follows:
    >
    > <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
    > SelectMethod="GetCampaigns"
    > TypeName="B3.Mailer.BusinessEntities.Campaign"
    > DataObjectTypeName="B3.Mailer.BusinessEntities.Campaign"
    > InsertMethod="Insert" UpdateMethod="Update">
    > <SelectParameters>
    > <asp:SessionParameter Name="clientId"
    > SessionField="ClientId"
    > Type="Int32" />
    > </SelectParameters>
    > </asp:ObjectDataSource>
    > The update method is defined as:
    >
    > public static void Update(Campaign campaign)
    > {
    > }
    > However, when I edit a row in the GridView and press the update button
    > I get the following error:
    >
    > [InvalidOperationException: Cannot convert value of parameter
    > 'CreateDate'
    > from 'System.String' to 'System.DateTime']
    > System.Web.UI.WebControls.ObjectDataSourceView.ConvertType(Object
    > value,
    > Type type, String paramName) +485
    >
    > System.Web.UI.WebControls.ObjectDataSourceView.BuildObjectValue(Object
    > value, Type destinationType, String paramName) +217
    > System.Web.UI.WebControls.ObjectDataSourceView.BuildDataObject(Type
    > dataObjectType, IDictionary inputParameters) +548
    >
    > System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictiona
    > ry
    > keys, IDictionary values, IDictionary oldValues) +1520
    > System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary
    > values,
    > IDictionary oldValues, DataSourceViewOperationCallback callback) +179
    > System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row,
    > Int32
    > rowIndex, Boolean causesValidation) +1137
    > System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
    > causesValidation, String validationGroup) +835
    > System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source,
    > EventArgs
    > e) +162
    > System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
    > args) +56
    > System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source,
    > EventArgs e) +118
    > System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
    > args) +56
    > System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e)
    > +106
    > System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String
    > eventArgument) +200
    > System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHand
    > ler.RaisePostBackEvent(String eventArgument) +31
    > System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    > sourceControl, String eventArgument) +32
    > System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    > +72
    > System.Web.UI.Page.ProcessRequestMain(Boolean
    > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    > +3840
    > This appears to be caused by the date being in UK format (dd/mm/yyyy -
    > which is correct for this application) as dates which could also be in
    > US format (i.e. 12/12/2005) do not throw this error.
    >
    > Both my browser and development machine are set to en-gb but there is
    > no Culture attribute set on the @Page tags on the page.
    >
    > Is this a bug in the ObjectDataSource not conforming to globalization
    > or am I missing somthing?
    >
    > Any help you can give will be much appreciated. Thanks in advance for
    > your help.
    >
    > Regards,
    >
    > Anne.
    >
     
    Brock Allen, Dec 14, 2005
    #2
    1. Advertising

  3. Alas no, this isn't my problem. As you will see HtmlEncode is set to false
    and the formating string does work as expected, including working correctly
    with the culture and displaying dd/mm/yyyy.

    This issue is simply with, what appears to be, a data conversion bug when an
    edited row is updated.

    Anne.

    "Brock Allen" wrote:

    > Perhaps this is your problem:
    >
    > http://wintellect.com/WEBLOGS/wintellect/archive/2005/11/17/2363.aspx
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    > > Hi,
    > >
    > > I have an british ASP.Net 2.0 application which is doing what (should)
    > > be very simple. But I am having issues.
    > >
    > > On my page I have a GridView as follows (some tags excluded for easy
    > > reading):
    > >
    > > <asp:GridView ID="GridView1" runat="server"
    > > AutoGenerateColumns="False"
    > > DataSourceID="ObjectDataSource1" DataKeyNames="Id"
    > > OnRowUpdated="GridView1_RowUpdated">
    > > <Columns>
    > > <asp:BoundField DataField="CreateDate" HeaderText="Create
    > > Date"
    > > SortExpression="CreateDate"
    > > DataFormatString="{0:d}" ApplyFormatInEditMode="True"
    > > ReadOnly="True" HtmlEncode="False">
    > > <HeaderStyle Wrap="False" />
    > > </asp:BoundField>
    > > <asp:CommandField ButtonType="Image"
    > > CancelImageUrl="~/images/manager/false.gif"
    > > EditImageUrl="~/images/manager/edit.gif"
    > > ShowEditButton="True" UpdateImageUrl="~/images/manager/true.gif" />
    > > </Columns>
    > > </asp:GridView>
    > > This is bound to an ObjectDataSource defined as follows:
    > >
    > > <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
    > > SelectMethod="GetCampaigns"
    > > TypeName="B3.Mailer.BusinessEntities.Campaign"
    > > DataObjectTypeName="B3.Mailer.BusinessEntities.Campaign"
    > > InsertMethod="Insert" UpdateMethod="Update">
    > > <SelectParameters>
    > > <asp:SessionParameter Name="clientId"
    > > SessionField="ClientId"
    > > Type="Int32" />
    > > </SelectParameters>
    > > </asp:ObjectDataSource>
    > > The update method is defined as:
    > >
    > > public static void Update(Campaign campaign)
    > > {
    > > }
    > > However, when I edit a row in the GridView and press the update button
    > > I get the following error:
    > >
    > > [InvalidOperationException: Cannot convert value of parameter
    > > 'CreateDate'
    > > from 'System.String' to 'System.DateTime']
    > > System.Web.UI.WebControls.ObjectDataSourceView.ConvertType(Object
    > > value,
    > > Type type, String paramName) +485
    > >
    > > System.Web.UI.WebControls.ObjectDataSourceView.BuildObjectValue(Object
    > > value, Type destinationType, String paramName) +217
    > > System.Web.UI.WebControls.ObjectDataSourceView.BuildDataObject(Type
    > > dataObjectType, IDictionary inputParameters) +548
    > >
    > > System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictiona
    > > ry
    > > keys, IDictionary values, IDictionary oldValues) +1520
    > > System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary
    > > values,
    > > IDictionary oldValues, DataSourceViewOperationCallback callback) +179
    > > System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row,
    > > Int32
    > > rowIndex, Boolean causesValidation) +1137
    > > System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
    > > causesValidation, String validationGroup) +835
    > > System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source,
    > > EventArgs
    > > e) +162
    > > System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
    > > args) +56
    > > System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source,
    > > EventArgs e) +118
    > > System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
    > > args) +56
    > > System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e)
    > > +106
    > > System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String
    > > eventArgument) +200
    > > System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHand
    > > ler.RaisePostBackEvent(String eventArgument) +31
    > > System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    > > sourceControl, String eventArgument) +32
    > > System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    > > +72
    > > System.Web.UI.Page.ProcessRequestMain(Boolean
    > > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    > > +3840
    > > This appears to be caused by the date being in UK format (dd/mm/yyyy -
    > > which is correct for this application) as dates which could also be in
    > > US format (i.e. 12/12/2005) do not throw this error.
    > >
    > > Both my browser and development machine are set to en-gb but there is
    > > no Culture attribute set on the @Page tags on the page.
    > >
    > > Is this a bug in the ObjectDataSource not conforming to globalization
    > > or am I missing somthing?
    > >
    > > Any help you can give will be much appreciated. Thanks in advance for
    > > your help.
    > >
    > > Regards,
    > >
    > > Anne.
    > >

    >
    >
    >
     
    Anne Catterick, Dec 14, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QW5uZSBDYXR0ZXJpY2s=?=

    ObjectDataSource DateTime isuue with en-gb culture

    =?Utf-8?B?QW5uZSBDYXR0ZXJpY2s=?=, Dec 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,804
    =?Utf-8?B?QW5uZSBDYXR0ZXJpY2s=?=
    Dec 15, 2005
  2. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    758
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  3. Tim Peters
    Replies:
    0
    Views:
    596
    Tim Peters
    Sep 9, 2003
  4. mp
    Replies:
    1
    Views:
    439
    John Machin
    Jul 28, 2006
  5. Martin
    Replies:
    0
    Views:
    375
    Martin
    Dec 27, 2008
Loading...

Share This Page