Reputation: 13
I'm trying to display a property (myCar.Make) on a web form using the simpliest way, e.g. a literal control.
But I get errors.
How to do achieve this?
protected void Page_Load(object sender, EventArgs e)
{
Car myCar = new Car();
myCar.Make = "BMW";
myCar.Model = "745li";
myCar.Color = "Black";
myCar.Year = 2005;
Literal1.Text = "Car Make: {0}", myCar.Make;
}
Upvotes: 0
Views: 25
Reputation: 16733
It looks like you are trying to format your string, but you need to call String.Format()
to get it to work:
Literal1.Text = String.Format("Car Make: {0}", myCar.Make);
Upvotes: 1
Reputation: 14470
Literal1.Text = "Car Make: " + myCar.Make;
or
Literal1.Text = string.Format("Car Make: {0}", myCar.Make);
Upvotes: 1