Localized two way date binding RRS feed

  • Question

  • User-1939834628 posted

    I defined a GridView in this way:

            <asp:TemplateField HeaderText="Date">
                    <asp:Label runat="server" Text='<%# Eval("event_date","{0:dd/MM/yyyy}") %>' />
                     <asp:TextBox ID="txtDate" runat="server" Text='<%# Bind("event_date","{0:dd/MM/yyyy}") %>' />
          <asp:TemplateField ItemStyle-HorizontalAlign="Right">
              <asp:ImageButton ID="btnDelete" runat="server" ImageUrl="/IMAGES/ico_cancella.gif" CommandName="Delete" CommandArgument='<%# Eval("id") %>' OnCommand="btnDelete_Command" CausesValidation="false" />
                  <asp:ImageButton ID="btnEdit" runat="server" ImageUrl="/IMAGES/ico_modifica.gif" CommandName="Edit" CommandArgument='<%# Eval("id") %>' OnCommand="btnEdit_Command" CausesValidation="false" />
                   <asp:ImageButton ID="btnUpdate" runat="server" ImageUrl="/IMAGES/ico_close.gif" CommandName="Update" CommandArgument='<%# Eval("id") %>' OnCommand="btnUpdate_Command" ValidationGroup="vgUpdate" />
                   <asp:ImageButton ID="btnCancelUpdate" runat="server" ImageUrl="/IMAGES/ico_annulla.png" CommandName="Cancel" OnCommand="btnCancelUpdate_Command" CausesValidation="false" />
           </asp:TemplateField> </Columns> </asp:GridView>

    I cannot update the row since an exception is thrown about date field format.

    I tried removing the format qualifier from Bind() call but in such case:

    1) the date field is formatted the same way (italian localization) but it contains also hh:mm:ss ...

    2) and the update also fails with the same error

    The DataSource is an SQLDataSource and the SQL backend is a MySQL server.

    Thnx in advance.

    Thursday, March 18, 2021 5:55 PM


  • User-1939834628 posted

    I noticed that the SQLDataSource was missing a key part, in UpdateParameters I forgot to specify the event_date field (and some other) .. suprizingly update was working (except for the missing date format management):

                <asp:Parameter Name="id" Direction="Input" DbType="Int32" ConvertEmptyStringToNull="true" DefaultValue="" />
                <asp:Parameter Name="event_date" Direction="Input" DbType="Date" ConvertEmptyStringToNull="true" DefaultValue="" />

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 18, 2021 6:25 PM