Datagrid Databind "System.FormatException: Input string was not in a correct format"

B

bnlockwood

G'day all,

Thank you in advance for anyone that can help.

I have a shopping cart datagrid on my c# asp.net page.
This is the code:

-------------------------------------

<asp:datagrid id="grdShoppingCart" OnItemDataBound="ItemDB"
ShowFooter="True" AutoGenerateColumns="False" Runat="server"
BorderStyle="None" Width="788px" GridLines="None">
<ItemStyle Font-Size="X-Small" Height="50px"
BackColor="White"></ItemStyle>
<HeaderStyle Font-Size="X-Small" Font-Names="Arial" Height="35px"
ForeColor="White" BackColor="DimGray"></HeaderStyle>

<Columns>
<asp:TemplateColumn HeaderText="Base Part#">
<ItemTemplate>
<asp:Label Runat="server" ID="Product"><%#DataBinder.Eval(Container,
"DataItem.product_nm")%></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="cart_product_unit_cost" HeaderText="Unit
Cost" DataFormatString="{0:C}"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Qty">
<ItemTemplate>
<asp:TextBox Width="90px" Runat=server
Text='<%#DataBinder.Eval(Container, "DataItem.cart_product_qty")%>'
ID="Quantity" /> </ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="cart_product_total_cost" HeaderText="Unit
Total Cost"></asp:BoundColumn>
</Columns>
</asp:datagrid>

------------------------------------- << This works

But when I try to add another column like

<asp:TemplateColumn HeaderText="Description">
<ItemTemplate>
<asp:TextBox Runat=server Text='<%#DataBinder.Eval(Container,
"DataItem.product_desc")%>' ID="Description" /> </ItemTemplate>
</asp:TemplateColumn>

it errors with a System.FormatException: Input string was not in a
correct format.
I've even tried entering a simple.

<asp:TemplateColumn HeaderText="Description">
<ItemTemplate>
<asp:TextBox Runat=server Text='This is a description'
ID="Description" /> </ItemTemplate>
</asp:TemplateColumn>

Can anyone enlighten me as to what I'm doing wrong? I guess I can rule
out any database stuff because even if I type the static description it
errors as well.

Any advice or help would really be appreciated.
Kind regards,
Brian
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top