DataBinding & the ObjectList Control (Mobile)

Discussion in 'ASP .Net' started by Guest, Sep 4, 2007.

  1. Guest

    Guest 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" >
    <mobile:Image ImageUrl="" Runat="server" />
    <mobile:Label Runat="server">
    <%# Eval("ID") %>
    <mobile:Label Runat="server">
    <%# Eval("UserTitle") %>
    <br />
    <Field Title="ID" DataField="ID" />
    <Field Title="UserTitle" DataField="UserTitle" />

    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!

    Guest, Sep 4, 2007
    1. Advertisements

  2. Guest

    Guest 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

    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?

    Guest, Sep 4, 2007
    1. Advertisements

  3. 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.
    <%# MyFunction((int)Eval("ID")) %>
    Muhammad Naveed Yaseen, Sep 5, 2007
  4. Guest

    Guest Guest

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


    Guest, Sep 5, 2007
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.