Home All Groups Group Topic Archive Search About

Using if on ASPX-side instead of in code behind

Author
8 Jul 2009 9:05 AM
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?)

--
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.

Author
8 Jul 2009 12:24 PM
Wolfgang Kluge
Show quote Hide quote
"K Viltersten" <t***@viltersten.com> schrieb im Newsbeitrag
news:7bj5rfF23ofibU1@mid.individual.net...
>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/
Are all your drivers up to date? click for free checkup

Author
8 Jul 2009 3:18 PM
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: nse***@eprocorp.com 

Warm Regards,
N.Sendu.
E*pro.
Author
8 Jul 2009 12:28 PM
Gregory A. Beamer
"K Viltersten" <t***@viltersten.com> wrote in news:7bj5rfF23ofibU1
@mid.individual.net:

Show quoteHide quote
> 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.


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

******************************************
Show quoteHide quote
|     Think outside the box!             |
******************************************
Author
8 Jul 2009 3:19 PM
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: nse***@eprocorp.com 

Warm Regards,
N.Sendu.
E*pro.
Author
8 Jul 2009 3:17 PM
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: nse***@eprocorp.com 

Warm Regards,
N.Sendu.
E*pro.

Bookmark and Share