locked
Localized two way date binding RRS feed

  • Question

  • User-1939834628 posted

    I defined a GridView in this way:

    <asp:GridView
         ID="gvData"
         runat="server"
         DataSourceID="sdsData"
         AutoGenerateColumns="False"
        <Columns>
            <asp:TemplateField HeaderText="Date">
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Eval("event_date","{0:dd/MM/yyyy}") %>' />
                  </ItemTemplate>
                  <EditItemTemplate>
                     <asp:TextBox ID="txtDate" runat="server" Text='<%# Bind("event_date","{0:dd/MM/yyyy}") %>' />
                   </EditItemTemplate>
            </asp:TemplateField>
          <asp:TemplateField ItemStyle-HorizontalAlign="Right">
          <ItemTemplate>
              <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" />
              </ItemTemplate>
               <EditItemTemplate>
                   <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" />
                </EditItemTemplate>
           </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

Answers

  • 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):

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



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