DataBinding & the ObjectList Control (Mobile)

G

Guest

Hi. I have finally figured out the basics of the ObjectList control that I'm
using for Mobile. Now I need help with some stuff that's a little more
complex in actually binding data.

Let's say that I have a Default.aspx and a Default.aspx.cs. On the
Default.aspx I have created an ObjectList that looks like:

<mobile:ObjectList ID="PicsOL" Runat="server"
CommandStyle-StyleReference="subcommand" AutoGenerateFields="true"
LabelStyle-StyleReference="title" >
<DeviceSpecific>
<Choice>
<ItemTemplate>
<mobile:Image ImageUrl="" Runat="server" />
<mobile:Label Runat="server">
<%# Eval("ID") %>
</mobile:Label>
<mobile:Label Runat="server">
<%# Eval("UserTitle") %>
</mobile:Label>
<br />
</ItemTemplate>
</Choice>
</DeviceSpecific>
<Field Title="ID" DataField="ID" />
<Field Title="UserTitle" DataField="UserTitle" />
</mobile:ObjectList>

But I have a question: Let's say that I want to do something simple but a
little more complicated than just Eval("ID"). What If I want to run the value
of ID through a function that I have created (say, on my .cs code-behind
page). Let's say the function is something like
int MyFunction(int ID)
How do I get that into the <%# %> of the data-bound item in the list? I've
tried lots of different global objects and noting works. Says the server tag
is not well formed.

I know that this is doable, but I don't really understand the syntax.

Help much appreciated!

Alex
 
G

Guest

Well, I have beat my head against this enough and have figured out the my
whole problem was that when I used the syntax

<mobile:Image
ImageUrl="<%# TestClass.SomeFunction(Convert.ToInt32(Eval("ID"))) %>"
Runat="server" />

I get a "Server Tag not well formed" error. If I stick this same binding tag
OUTSIDE of the Property of a tag (like as the text in a Mobile Lable control)
it works just fine.

This is strange because I specifically remember, in non-Mobile ASPXs, puting
<%# %> tags inside the quotation marks of the properties of controls I placed
in my list controls.

How come this doesn't work here?

Alex
 
M

Muhammad Naveed Yaseen

ImageUrl="<%# TestClass.SomeFunction(Convert.ToInt32(Eval("ID"))) %>"

Double-quotes meant for ImageUrl are colliding with double-quotes
meant for Eval("ID"). Replace outer double-quotes with single-quotes
and it should work.
But I have a question: Let's say that I want to do something simple but a
little more complicated than just Eval("ID"). What If I want to run the value
of ID through a function that I have created (say, on my .cs code-behind
page). Let's say the function is something like int MyFunction(int ID)

<%# MyFunction((int)Eval("ID")) %>
 
G

Guest

D'oh!!! How stupid of me. Thanks!

Alex

Muhammad Naveed Yaseen said:
Double-quotes meant for ImageUrl are colliding with double-quotes
meant for Eval("ID"). Replace outer double-quotes with single-quotes
and it should work.


<%# MyFunction((int)Eval("ID")) %>
 

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,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top