Results 1 to 3 of 3

Thread: Datalist and template

  1. #1

    Thread Starter
    Hyperactive Member MarkusJ_NZ's Avatar
    Join Date
    Jun 2001
    Posts
    375

    Datalist and template

    Hi, I have a datalist that is used in conjunction to display values
    retrieved from a database:

    What I would like to do is check the value of a field and then do something
    (Change a label or whatever).
    Below is my code
    VB Code:
    1. ' Create a datalist
    2. <asp:DataList id="MyList" RepeatColumns="2" runat="server">
    3.          <ItemTemplate>
    4.           <table border="0" width="272">
    5.            <tr>
    6.             <td width="25">
    7.              &nbsp
    8.             </td>
    9. ' I would like to check the value of the following item and then do
    10. ' something if the item is less than 0
    11. ' e.g  if DataBinder.Eval(Container.DataItem, "UnitCost", "{0:c}") < 0
    12. ' then response.write("hi")
    13.              <span class="ProductListItem">
    14.               <%# DataBinder.Eval(Container.DataItem, "UnitCost", "{0:c}")
    15. %>
    16.              </span>

    Any help appreciated

    Cheers
    Mark

  2. #2
    Fanatic Member Redth's Avatar
    Join Date
    May 2001
    Location
    Ontario, Canada
    Posts
    551
    you could put a Label in the ItemTemplate, fill it with your initial unchecked value:

    <asp:Label Runat="server" ID="lblUnitCost" Text='<%# Container.DataItem("UnitPrice") %>' Visible="False" />

    Then loop through all your Items in the Datalist, and then check the value in the label... then do something with it then depending on what you need to do I don't think you can have Conditional statements in the ItemTemplate... :/ i could be wrong though, but i seem to remember trying to do something similar, and it wouldn't let me use an If Then Statement....

  3. #3

    Thread Starter
    Hyperactive Member MarkusJ_NZ's Avatar
    Join Date
    Jun 2001
    Posts
    375

    Resolved

    Hi, I have found a way to do it using a function. Apparantly you can call a function but not a subroutine from inside a template.

    more info here

    http://aspalliance.com/Colt/Articles/Article1.aspx

    Thanks for your help
    Regards
    Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width