<#% eval %> - possible?

M

Mike

Is it possible to do this in the HTML of the aspx page?

<#% if Eval("Name") != null %>
write something here
<#% else %>
show message for missing name
<#% end if %>


when I try this I get errors for missing (, or IF is not recognized, etc.

how can I get this to work without adding it to the code behind? I need to do this in a GridView that is using template fields with links in the fields
 
J

Juan Romero

I am not sure if this is possible but I recommend you avoid this style of
coding. Put all code in your code behind page so you have a clean separation
of layers.

Is it possible to do this in the HTML of the aspx page?

<#% if Eval("Name") != null %>
write something here
<#% else %>
show message for missing name
<#% end if %>


when I try this I get errors for missing (, or IF is not recognized, etc.

how can I get this to work without adding it to the code behind? I need to
do this in a GridView that is using template fields with links in the fields
 
M

Mike

I would rather not do this either but the grid is binding to a dataset and I
really can't teak with that too much
 
B

bruce barker

no. <%# %> is a binding expression and can only be used to specify a
property value of a server control (prop="<%# expression%>"). also it
must be an expression, not a statement.

you gave no sample of what you are trying to do, so its hard to give an
answer.


-- bruce (sqlwork.com)
 
M

Mike

you gave no sample of what you are trying to do, so its hard to give an

yeah I did: it was in my first post:

I need to show an particular image if the person exists in the db or not and
the developer that created this page is using a dataset to bind the grid but
in the html is using template fields and is using the <%# %> for every
template field in the grid.

<#% if Eval("Name") != null %>
write something here
<#% else %>
show message for missing name
<#% end if %>
 
G

George Ter-Saakov

You will have to create your own function for that in a code behind

like
public string GetName(object objName)
{
if( objName == null )
return "No Name";
else
return (string)objName;
}

and call it

<%# GetName(Eval("Name")) %>


George
Is it possible to do this in the HTML of the aspx page?

<#% if Eval("Name") != null %>
write something here
<#% else %>
show message for missing name
<#% end if %>


when I try this I get errors for missing (, or IF is not recognized, etc.

how can I get this to work without adding it to the code behind? I need to do this in a GridView that is using template fields with links in the fields
 
M

Mike

OK, I'll give it a shot, and see if it will show the correct image based on the value passed to the routine
You will have to create your own function for that in a code behind

like
public string GetName(object objName)
{
if( objName == null )
return "No Name";
else
return (string)objName;
}

and call it

<%# GetName(Eval("Name")) %>


George
Is it possible to do this in the HTML of the aspx page?

<#% if Eval("Name") != null %>
write something here
<#% else %>
show message for missing name
<#% end if %>


when I try this I get errors for missing (, or IF is not recognized, etc.

how can I get this to work without adding it to the code behind? I need to do this in a GridView that is using template fields with links in the fields
 
G

George Ter-Saakov

That is how I always do.

Also I usually put those type of functions into <script runat=server"> on the aspx page itself rather than have them in .CS files
Since I think they relate to GUI. Except the cases when I need to have standardized output across web site.

I usually have static functions in my clsGlobal: OutputDate(), OutputMoney(). Thus I can switch my date format or currency in one place for every page pretty painlessly.




George.

OK, I'll give it a shot, and see if it will show the correct image based on the value passed to the routine
You will have to create your own function for that in a code behind

like
public string GetName(object objName)
{
if( objName == null )
return "No Name";
else
return (string)objName;
}

and call it

<%# GetName(Eval("Name")) %>


George
Is it possible to do this in the HTML of the aspx page?

<#% if Eval("Name") != null %>
write something here
<#% else %>
show message for missing name
<#% end if %>


when I try this I get errors for missing (, or IF is not recognized, etc.

how can I get this to work without adding it to the code behind? I need to do this in a GridView that is using template fields with links in the fields
 
M

Mike

it worked for my scenario, thanks.

I'll keep that in mind for the future, thanks
That is how I always do.

Also I usually put those type of functions into <script runat=server"> on the aspx page itself rather than have them in .CS files
Since I think they relate to GUI. Except the cases when I need to have standardized output across web site.

I usually have static functions in my clsGlobal: OutputDate(), OutputMoney(). Thus I can switch my date format or currency in one place for every page pretty painlessly.




George.

OK, I'll give it a shot, and see if it will show the correct image based on the value passed to the routine
You will have to create your own function for that in a code behind

like
public string GetName(object objName)
{
if( objName == null )
return "No Name";
else
return (string)objName;
}

and call it

<%# GetName(Eval("Name")) %>


George
Is it possible to do this in the HTML of the aspx page?

<#% if Eval("Name") != null %>
write something here
<#% else %>
show message for missing name
<#% end if %>


when I try this I get errors for missing (, or IF is not recognized, etc.

how can I get this to work without adding it to the code behind? I need to do this in a GridView that is using template fields with links in the fields
 

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

Forum statistics

Threads
473,995
Messages
2,570,235
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top