Variables in the HTML part of a web form...

G

Guest

The DBA team at the office controls the naming conventions for the database
structure, but their naming convention are rather tedious. So typically I
create a global module that I use as a mapping file to create constants with
more appropriate field and table names and map them to the table and field
names required by the DB team. But now, using a DataList, I'm having a
problem. How can I use a variable name to indicate the field name in the
HTML that's rendered by the DataList control?

Rather than

<%# DataBiner.Eval(Container.DataItem, "T003_EntityName_String") %>

I want to use

<%# DataBiner.Eval(Container.DataItem, EName) %>

Where EName is a global var defined in a separate module.

Is there a way to do this? I'm getting complaints that EName isn't a valid
column name...

Thanks.

Jerry
 
K

Karl Seguin

Well, assuming EName is defined something like:

public class DatabaseColumn
public const EName as string = "T003_EntityName_String"
end class

you should be able to simply do:

<%# DataBiner.Eval(Container.DataItem, DatabaseColumn.EName) %>

IF DatabaseColumn is in a separate namespace than the page, you'll need to
either fully reference the namespace OR @Import the namespace.

Karl
 
S

Scott M.

I'm not sure this approach will work. At runtime, wouldn't this look to
bind to EName, which has a value of "T003_EntityName_String",
and therefore that is the data you'd get back, not the data that
"T003_EntityName_String" refers to?
 
K

Karl Seguin

Granted, I haven't tried.

But Eval() is a method like any other. The 2nd parameter is the name of the
property/column it'll look up through reflection. If you pass "Hello" or a
variable with the value of "Hello", I'd expect to get the same result.

Karl
 
G

Guest

I guess I ended up doing something very similar. I didn't see your response
as this post never showed up in my newsreader. Hence the double post. Using
the web client, i see both posts.

I didn't use const and I had to declare an instance of the class in the code
behind in order for it to be recognized. Even tried it with shared vars, but
that didn't help.

It works as a class... Declare an instance of the class in the code module
and reference that var in the HTML.

Thanks for your input...
 
S

Scott M.

I understand and use DataBinder.Eval quite frequently. If you point it to a
constant that contains a string value, that string value is what it should
return.
 
S

Scott M.

Oops! I didn't notice the DatabaseColumn reference in the DataBind.Eval
statement. That makes more sense. Sorry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,133
Latest member
MDACVReview
Top