Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET/C# Decimal to 0.00
    text
    copied!<p>I got this method, how can I make the decimal to .00 and not .0000?</p> <pre><code> public static List&lt;Product&gt; GetAllProducts() { List&lt;Product&gt; products = new List&lt;Product&gt;(); string sqlQuery = "SELECT * FROM Products"; using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand(sqlQuery, connection)) { connection.Open(); using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { while (reader.Read()) { Product product = new Product(); product.Id = Convert.ToInt32(reader["Id"]); product.ManufacturerId = Convert.ToInt32(reader["ManufacturerId"]); product.CategoryId = Convert.ToInt32(reader["CategoryId"]); product.Name = (reader["Name"]).ToString(); product.Description = (reader["Description"]).ToString(); product.Price = Convert.ToDecimal(reader["Price"]); product.ItemsInStock = Convert.ToInt32(reader["ItemsInStock"]); products.Add(product); } } } } return products; } </code></pre> <p>UPDATE: Sorry for asking stupid questions. I can't see where to put the DataFormatString="{0:F2}"</p> <p>This is my grid:</p> <pre><code> &lt;asp:TemplateField HeaderText="Price" SortExpression="Price"&gt; &lt;EditItemTemplate&gt; &lt;asp:TextBox ID="PriceTextBox" runat="server" Text='&lt;%# Bind("Price") %&gt;'&gt;&lt;/asp:TextBox&gt; &lt;/EditItemTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="PriceLabel" runat="server" Text='&lt;%# Bind("Price") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload