Formview (EditView) Money Data Type Binding problem. Help....

Discussion in 'ASP .Net Web Controls' started by Sam, Jun 17, 2006.

  1. Sam

    Sam Guest

    Folks..


    I am trying to use a Simple form with 3 fields from SQL NorthWind
    Database (Order Details Table with 3 Fields. - OrderId, ProductId and
    Unit Price). The Field Unit Price has a data type of 'Money Type'.

    All I want is to able to edit/view/insert 'UnitPrice' field with 2
    decimal points instead of 4 decimal points.

    If I use: Bind("UnitPrice", "{0:c}") in Edit Template, I got: "Input
    string was not in a correct format...". Although this works in Item
    Template....

    I know I can do it easily in MS Access ADP Form where I set the Decimal

    Places 'Auto'. It works perfectly without any problem with the same SQL

    Datasource.

    I have been trying to use the same ADP logic in .net 2.0 Form View. No
    luck.....

    Below is my complete code. Any help/suggestions will be appreciated...
    I am also new to .net Environment....

    - Sam
    _________________

    <%@ Page Language="VB" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "<http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>">
    <script runat="server">
    </script>
    <html>
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    </div>
    <br />

    <br />
    <asp:FormView ID="FormView1" runat="server" AllowPaging="True"
    DataKeyNames="OrderID,ProductID"
    DataSourceID="SqlDataSource1" Width="256px">
    <EditItemTemplate>
    OrderID:
    <asp:Label ID="OrderIDLabel1" runat="server" Text='<%#
    Eval("OrderID") %>'></asp:Label><br />
    UnitPrice:
    <asp:TextBox ID="UnitPriceTextBox" runat="server"
    Text='<%# Bind("UnitPrice") %>'></asp:TextBox><br />
    ProductID:
    <asp:Label ID="ProductIDLabel1" runat="server"
    Text='<%# Eval("ProductID") %>'></asp:Label><br />
    <asp:LinkButton ID="UpdateButton" runat="server"
    CausesValidation="True" CommandName="Update"
    Text="Update">
    </asp:LinkButton>
    <asp:LinkButton ID="UpdateCancelButton" runat="server"
    CausesValidation="False" CommandName="Cancel"
    Text="Cancel">
    </asp:LinkButton>
    </EditItemTemplate>
    <InsertItemTemplate>
    OrderID:
    <asp:TextBox ID="OrderIDTextBox" runat="server"
    Text='<%# Bind("OrderID") %>'>
    </asp:TextBox><br />
    UnitPrice:
    <asp:TextBox ID="UnitPriceTextBox" runat="server"
    Text='<%# Bind("UnitPrice") %>'>
    </asp:TextBox><br />
    ProductID:
    <asp:TextBox ID="ProductIDTextBox" runat="server"
    Text='<%# Bind("ProductID") %>'>
    </asp:TextBox><br />
    <asp:LinkButton ID="InsertButton" runat="server"
    CausesValidation="True" CommandName="Insert"
    Text="Insert">
    </asp:LinkButton>
    <asp:LinkButton ID="InsertCancelButton" runat="server"
    CausesValidation="False" CommandName="Cancel"
    Text="Cancel">
    </asp:LinkButton>
    </InsertItemTemplate>
    <ItemTemplate>
    OrderID:
    <asp:Label ID="OrderIDLabel" runat="server" Text='<%#
    Eval("OrderID") %>'></asp:Label><br />
    UnitPrice:
    <asp:Label ID="UnitPriceLabel" runat="server" Text='<%#
    Bind("UnitPrice") %>'></asp:Label><br />
    ProductID:
    <asp:Label ID="ProductIDLabel" runat="server" Text='<%#
    Eval("ProductID") %>'></asp:Label><br />
    <asp:LinkButton ID="EditButton" runat="server"
    CausesValidation="False" CommandName="Edit"
    Text="Edit"></asp:LinkButton>
    <asp:LinkButton ID="DeleteButton" runat="server"
    CausesValidation="False" CommandName="Delete"
    Text="Delete"></asp:LinkButton>
    <asp:LinkButton ID="NewButton" runat="server"
    CausesValidation="False" CommandName="New"
    Text="New"></asp:LinkButton>
    </ItemTemplate>
    </asp:FormView>
    <br />
    <br />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString1 %>"
    DeleteCommand="DELETE FROM [Order Details] WHERE [OrderID]
    = @OrderID AND [ProductID] = @ProductID"
    InsertCommand="INSERT INTO [Order Details] ([OrderID],
    [UnitPrice], [ProductID]) VALUES (@OrderID, @UnitPrice, @ProductID)"
    SelectCommand="SELECT [OrderID], [UnitPrice], [ProductID]
    FROM [Order Details]"
    UpdateCommand="UPDATE [Order Details] SET [UnitPrice] =
    @UnitPrice WHERE [OrderID] = @OrderID AND [ProductID] = @ProductID">
    <DeleteParameters>
    <asp:parameter Name="OrderID" Type="Int32" />
    <asp:parameter Name="ProductID" Type="Int32" />
    </DeleteParameters>
    <UpdateParameters>
    <asp:parameter Name="UnitPrice" Type="Decimal" />
    <asp:parameter Name="OrderID" Type="Int32" />
    <asp:parameter Name="ProductID" Type="Int32" />
    </UpdateParameters>
    <InsertParameters>
    <asp:parameter Name="OrderID" Type="Int32" />
    <asp:parameter Name="UnitPrice" Type="Decimal" />
    <asp:parameter Name="ProductID" Type="Int32" />
    </InsertParameters>
    </asp:SqlDataSource>
    </form>
    </body>
    </html>
     
    Sam, Jun 17, 2006
    #1
    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. Jensen bredal
    Replies:
    3
    Views:
    7,579
    M. Posseth
    Jun 16, 2004
  2. Sam
    Replies:
    1
    Views:
    8,942
    Prnda76
    Feb 11, 2010
  3. Batista, Facundo

    Money data type

    Batista, Facundo, Sep 17, 2003, in forum: Python
    Replies:
    3
    Views:
    388
    Asun Friere
    Sep 18, 2003
  4. David Thielen

    FormView/Repeater/ Eval(FormView data)

    David Thielen, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    711
    David Thielen
    Jun 16, 2006
  5. Alex Luya
    Replies:
    1
    Views:
    296
Loading...

Share This Page