Hi i got this method, how can i make the decimal to .00 and not .0000 ? :)
public static List<Product> GetAllProducts()
{
List<Product> products = new List<Product>();
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;
}
UPDATE: Sorry for asking stupid questiens. i can't se where to put the DataFormatString="{0:F2}"
This is my grid:
<asp:TemplateField HeaderText="Price" SortExpression="Price">
<EditItemTemplate>
<asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="PriceLabel" runat="server" Text='<%# Bind("Price") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>