DataBinding & the ObjectList Control (Mobile)

Discussion in 'ASP .Net' started by =?Utf-8?B?QWxleCBNYWdoZW4=?=, Sep 4, 2007.

  1. 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
     
    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Sep 4, 2007
    #1
    1. Advertising

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

    "Alex Maghen" wrote:

    > 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
     
    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Sep 4, 2007
    #2
    1. Advertising

  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.

    > 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")) %>
     
    Muhammad Naveed Yaseen, Sep 5, 2007
    #3
  4. D'oh!!! How stupid of me. Thanks!

    Alex

    "Muhammad Naveed Yaseen" wrote:

    > > 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")) %>
    >
    >
     
    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Sep 5, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JJ
    Replies:
    0
    Views:
    368
  2. chen selina
    Replies:
    0
    Views:
    1,363
    chen selina
    Jul 13, 2010
  3. Mathasu

    Edit fields in a mobile:ObjectList

    Mathasu, Aug 5, 2004, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    153
    Mathasu
    Aug 5, 2004
  4. Mathasu

    mobile:objectlist

    Mathasu, Aug 19, 2004, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    165
    Mathasu
    Aug 19, 2004
  5. Mathasu

    Mobile:ObjectList and Custom Pagination

    Mathasu, Sep 17, 2004, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    247
    Mathasu
    Sep 17, 2004
Loading...

Share This Page