Using if on ASPX-side instead of in code behind

K

K Viltersten

I have the following script consisting of
three script-sections.

<% if (true) { %>
<%# MyLogic.GetName(
DataBinder.GetPropertyValue((List<MyInfo>)
Container.DataItem)[0], "PropName")) %>
<% } %>

I'd like to make it into a single one, similarly
to the example below. The name Container isn't
recognized, the computer tells me, though.

<%
if (true) {
MyLogic.GetName(
DataBinder.GetPropertyValue(((List<MyInfo>)
Container.DataItem)[0], "PropName"));
}
%>

What do i miss? What's the exact syntax here?

(I know that the best choice is to do that from
code behind and i intend to solve it that way.
However, i'm curious of how to make the above
work without code behind. It IS doable, right?)
 
W

Wolfgang Kluge

K Viltersten said:
I have the following script consisting of three script-sections.

<% if (true) { %>
<%# MyLogic.GetName(
DataBinder.GetPropertyValue((List<MyInfo>)
Container.DataItem)[0], "PropName")) %>
<% } %>

I'd like to make it into a single one, similarly
to the example below. The name Container isn't
recognized, the computer tells me, though.

<% if (true) { MyLogic.GetName(
DataBinder.GetPropertyValue(((List<MyInfo>)
Container.DataItem)[0], "PropName"));
} %>

What do i miss? What's the exact syntax here?

(I know that the best choice is to do that from
code behind and i intend to solve it that way.
However, i'm curious of how to make the above
work without code behind. It IS doable, right?)

--
Regards
K Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.


Hi K, ;)

"Container" is only available in <%# - blocks (within a data binding
expression). But in these, you can't use the if-statement. You are only
allowed to use expressions that returns a value.
So there's no chance to combine them this way... but you can use "? :"- or a
codebehind member instead (if it helps)
http://msdn.microsoft.com/en-us/library/bda9bbfx(VS.71).aspx


Sorry for my bad english...
Greets, Wolfgang Kluge
http://gehirnwindung.de/
http://klugesoftware.de/
 
G

Gregory A. Beamer

I have the following script consisting of
three script-sections.

<% if (true) { %>
<%# MyLogic.GetName(
DataBinder.GetPropertyValue((List<MyInfo>)
Container.DataItem)[0], "PropName")) %>
<% } %>

I'd like to make it into a single one, similarly
to the example below. The name Container isn't
recognized, the computer tells me, though.

<%
if (true) {
MyLogic.GetName(
DataBinder.GetPropertyValue(((List<MyInfo>)
Container.DataItem)[0], "PropName"));
}
%>

What do i miss? What's the exact syntax here?

(I know that the best choice is to do that from
code behind and i intend to solve it that way.
However, i'm curious of how to make the above
work without code behind. It IS doable, right?)

Container is a special construct when a control is data bound. It is
normally used to declaratively bind a particular data column to a
control that binds many elements, like a Repeater, DataList, GridView,
etc. And, when you do this, you use a special syntax:

<%# %>

The # here is important, although I forget all of the specifics of this.
At one time, it was dubbed simple data binding, whereas using the events
was complex data binding.

Once you move to <% %>, you are essentially coding as if you are using
code behind.

There are two ways to solve this that I can think of off hand:

1. To simple bind, use the element only. Then properly trim out the !
true (false) elements. This is essentially altering the dataset, linq
objects (etc) prior to bind

2. Use the row binding event to determine whether to display or not.

I am not sure you can easily mix the DataBinder logic with code as you
have, or at least not easily, as the parser would not recognize the
mixture.
 
R

Recruitment !!!

Hi,

I am sendu an recruiter from E*pro.

Nice to have a glance every day in this community and its people. Happy to
observe its concept and postings. I am working with a recruiting firm and
recruiting people in various IT,Accounting,ITES and other domains. I need
updated resume from people in Various parts of US. I can help them in getting
a better oppurtinity in any field of their aspiration.

Mail ur updated CV to: (e-mail address removed)

Warm Regards,
N.Sendu.
E*pro.
 
R

Recruitment !!!

Hi,

I am sendu an recruiter from E*pro.

Nice to have a glance every day in this community and its people. Happy to
observe its concept and postings. I am working with a recruiting firm and
recruiting people in various IT,Accounting,ITES and other domains. I need
updated resume from people in Various parts of US. I can help them in getting
a better oppurtinity in any field of their aspiration.

Mail ur updated CV to: (e-mail address removed)

Warm Regards,
N.Sendu.
E*pro.
 
R

Recruitment !!!

Hi,

I am sendu an recruiter from E*pro.

Nice to have a glance every day in this community and its people. Happy to
observe its concept and postings. I am working with a recruiting firm and
recruiting people in various IT,Accounting,ITES and other domains. I need
updated resume from people in Various parts of US. I can help them in getting
a better oppurtinity in any field of their aspiration.

Mail ur updated CV to: (e-mail address removed)

Warm Regards,
N.Sendu.
E*pro.
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top