11

Possible Duplicate:
Meaning of the various symbols in .aspx page of asp.net

I'm familiar with <%= "whatever" %> as a shortcut for <% Response.Write("whatever"); %>.

But I've recently come across some code that uses <%# %> instead. In this particular codebase, it's only being used inside of an <asp:Repeater /> but I

What does <%# %> do and when can/should it be used?

Community
  • 1
  • 1
Mark Biek
  • 146,731
  • 54
  • 156
  • 201
  • It means you're binding some data element. The repeater probably has a data source which are being repeated inside of your control. – George Johnston Dec 02 '11 at 20:34
  • George, can you elaborate? My C#/ASP.NET skills are pretty basic. – Mark Biek Dec 02 '11 at 20:35
  • 1
    Data binding on a repeater control: http://msdn.microsoft.com/en-us/library/aa719636%28v=vs.71%29.aspx – George Johnston Dec 02 '11 at 20:36
  • 1
    @ChrisF, thanks for pointing that one out. I think this question should be closed rather than being deleted, just to have some additional search terms available. – Mark Biek Dec 02 '11 at 20:41
  • Marking as duplicate doesn't delete it. It will stay open as a duplicate and alternate search result. There's at least one more I think, but I can't find it because the search for `%>` doesn't work! – ChrisF Dec 02 '11 at 20:42

3 Answers3

11

<%# ... %>

Data-binding expressions are an important set of code delimiters, which are used to create a binding between a server control property and a data source.

More about it here:

ASP.NET Code Delimiters

Community
  • 1
  • 1
Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
2

Its used in conjunction with Databind.Eval as in <%# DataBinder.Eval(Container.DataItem, "Price") %>

Here is an MSDN page onthe matter

Ashok Padmanabhan
  • 2,110
  • 1
  • 19
  • 36
1

That's how you do "BINDING" you may want to do a google search on asp.net data binding also to if you are using something like system.web.htmlcontrols this is how you could also get at document variables by name when using javascript.

MethodMan
  • 18,625
  • 6
  • 34
  • 52