Ive got a problem with a snippet of VB Im trying to convert to C#. Its complicated because the problem is buried within a .aspx page. This page has a datagrid which display records from a SQL Server database. When I first set up this page, I had a problem that numeric values were displaying with unnecessary trailing zeros. The customer asked me to remove them. Sometimes the value will be something like 0.000012. Other times it would be 0.340000 Its in the latter example that I need to remove the trailing zeros. So its not a simple case of formatting to a fixed number of places. I wrote a function to remove trailing zeros from a string value. Heres the original code from my web page which called my function worked perfectly when I was using VB&&
<asp:TemplateColumn HeaderText="Price Each" >
<%# RemoveTrailingZeros(Container.DataItem("MyPriceEach")) %>
Now thatI am using C# as the page language, the above gives me a compilation error:
Non-invocable member 'System.Web.UI.WebControls.DataGridItem.DataItem' cannot be used like a method.
I have seen this before. It means that I have to change the round brackets for square ones. So I changed them thus:
<%# RemoveTrailingZeros(Container.DataItem["MyPriceEach"]) %>
Now I get a different error:
Cannot apply indexing with  to an expression of type 'object'
How do I fix this?