Eval function is C #
I need help understanding what the Eval bit does (just started learning C # .net):
<asp:Image ID="Image1" ImageUrl='<%# Eval("Name", "~/UploadImages/{0} %>' ... The image is in the data relay, which is tied to a folder containing image files.
I am confused with "Name" and {0}. What is their significance and in what situation can I change them.
The Eval operator in an aspx or ascx file is typically used to dynamically evaluate a binding operator in the context of an element bound to the current row in data control.
The first parameter is the property / field to bind to the string. The second parameter is an optional format string. {0} will replace the value of the Name property when rendering the output text.
Here is the doc . Enjoy it!
This is a format string. No matter what is evaluated by this property, let's call it evalResult, the first parameter of the eval is passed through String.Format("~/UploadImages/{0}", evalResult)
So, if the value in your data set field for the name is "Steve.jpg", your grid will show:<img src="/UploadImages/Steve.jpg" ... />
For more information on Eval, check msdn: http://msdn.microsoft.com/en-us/library/2d76z3ck.aspx
In this case, the contents of "Name" will be inserted into placeholder {0}.
So, if you have
Name = "ImageName" Your ImageUrl will be
ImageUrl="~/UploadImages/ImageName" This is useful in dynamic scenarios because for each object the relay will change the Name property accordingly to form the image URL.