Trim Function with Item Template

Discussion in 'ASP.NET / ASP.NET Core' started by davidseye, Mar 13, 2003.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I have populated a datalist from a database table and applied the results in the page with an item template. This is the code:

    <ASP:DataList id="NavLinkList" runat="server">
    <ItemTemplate>
    <table>
    <tr>
    <td valign="top">
    <a href="../<%# DataBinder.Eval(Container.DataItem, "navLink") %>" target="<%# DataBinder.Eval(Container.DataItem, "target") %>"><span style="font-size:8pt;color:white;text-decoration:none;"><%# DataBinder.Eval(Container.DataItem, "navText") %></span></a>
    </td>
    </tr>
    </table>
    </ItemTemplate>
    </ASP:DataList>

    What I need help with is this. The target value has extra white space which I would like to apply the trim function to remove, but all my attempts to now have proven futile. Can anyone suggest how I can trim this: <%# DataBinder.Eval(Container.DataItem, "target") %> ?

    Or perhaps I should bind the data to a different control: a hyperlink or a repeater. What do you think?
    Thanks
     
  2. Thanks Bruce. I rather thought that would be the case. I appreciate you taking the time to respond.
     
  3. Bruce

    Bruce DiscountASP.NET Staff

    I had the same problem when i was building an application.

    I spent about an hour trying to figure out host to include any code inside the <%# %>, but i couldn't find anything.

    What i did instead was to construct the table programatically and populate it with values.

    In your situation, you may also want to try clean the data table before you bind it to the datalist.

    Hope this helps.

    quote:Originally posted by davidseye

    I have populated a datalist from a database table and applied the results in the page with an item template. This is the code:

    <ASP:DataList id="NavLinkList" runat="server">
    <ItemTemplate>
    <table>
    <tr>
    <td valign="top">
    <a href="../<%# DataBinder.Eval(Container.DataItem, "navLink") %>" target="<%# DataBinder.Eval(Container.DataItem, "target") %>"><span style="font-size:8pt;color:white;text-decoration:none;"><%# DataBinder.Eval(Container.DataItem, "navText") %></span></a>
    </td>
    </tr>
    </table>
    </ItemTemplate>
    </ASP:DataList>

    What I need help with is this. The target value has extra white space which I would like to apply the trim function to remove, but all my attempts to now have proven futile. Can anyone suggest how I can trim this: <%# DataBinder.Eval(Container.DataItem, "target") %> ?

    Or perhaps I should bind the data to a different control: a hyperlink or a repeater. What do you think?
    Thanks
    </blockquote id="quote"></font id="quote">
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page