user3759748
user3759748

Reputation: 76

How to make a limit on a text that has been eval from database

my issue is i don't know how to make "tekst" only have 180 charecters. can anybody help me ? when it's eval and it's above 180 i have to cut it down to 180, and do a read more link.

<asp:Panel ID="biler_panel" runat="server" Visible="False">
                <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString1 %>" DeleteCommand="DELETE FROM [Artikler] WHERE [Id] = @Id" InsertCommand="INSERT INTO [Artikler] ([Navn], [Tekst], [Dato], [Vist], [Fk_kat]) VALUES (@Navn, @Tekst, @Dato, @Vist, @Fk_kat)" ProviderName="<%$ ConnectionStrings:DatabaseConnectionString1.ProviderName %>" SelectCommand="SELECT [Id], [Navn], [Tekst], [Dato], [Vist], [Fk_kat] FROM [Artikler]" UpdateCommand="UPDATE [Artikler] SET [Navn] = @Navn, [Tekst] = @Tekst, [Dato] = @Dato, [Vist] = @Vist, [Fk_kat] = @Fk_kat WHERE [Id] = @Id">
                    <DeleteParameters>
                        <asp:Parameter Name="Id" Type="Int32" />
                    </DeleteParameters>
                    <InsertParameters>
                        <asp:Parameter Name="Navn" Type="String" />
                        <asp:Parameter Name="Tekst" Type="String" />
                        <asp:Parameter Name="Dato" Type="DateTime" />
                        <asp:Parameter Name="Vist" Type="Int32" />
                        <asp:Parameter Name="Fk_kat" Type="String" />
                    </InsertParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="Navn" Type="String" />
                        <asp:Parameter Name="Tekst" Type="String" />
                        <asp:Parameter Name="Dato" Type="DateTime" />
                        <asp:Parameter Name="Vist" Type="Int32" />
                        <asp:Parameter Name="Fk_kat" Type="String" />
                        <asp:Parameter Name="Id" Type="Int32" />
                    </UpdateParameters>
                </asp:SqlDataSource>
            <asp:Repeater ID="Repeater5" runat="server" DataSourceID="SqlDataSource5">


                <ItemTemplate>

                    <div id="bilerdiv"><p class="overskrift"><%# Eval("Navn") %></p>
                        <p class="tid"><%# Eval("Dato") %></p>
                        <p class="tekst"><%#Eval ("Tekst") %></p>
                    </div>
                </ItemTemplate>

            </asp:Repeater>

Upvotes: 1

Views: 139

Answers (3)

BG100
BG100

Reputation: 4531

The CSS text-overflow property might help here. That way you don't have to anything, and let the browser do the work for you.

Upvotes: 0

chridam
chridam

Reputation: 103455

You could try:

<%# Eval("Tekst").ToString().PadRight(180).Substring(0, 180).TrimEnd() %>

Or using LINQ:

<%# Eval("Tekst").ToString().Take(180).Aggregate("", (x,y) => x + y) %>

EDIT: For a Read More link implementation, you can use jQuery assuming your markup will be as follows:

HTML:

<p class="tekst-limited"><%# Eval("Tekst").ToString().PadRight(180).Substring(0, 180).TrimEnd() %></p>
<p class="tekst-full"><%#Eval ("Tekst") %></p>
<a href="#" class="button"></a>

jQuery:

$(".button").click(function(){
  var moreAndLess = $("p").is(':visible') ? 'Read More' : 'Less';
  $(this).text(moreAndLess);
  $(".tekst-full").slideToggle();
});

Upvotes: 1

शेखर
शेखर

Reputation: 17614

What you can do you can show it on mouse over as title.

<div id="bilerdiv">
     <p class="overskrift" title='<%# Eval("Tekst").ToString()%>'>
         <%# Eval("Tekst").ToString().PadRight(180).Substring(0, 180).TrimEnd() %>
     </p>
     ......
 </div>

If it is greater than 180 character the 180 will be shown and all will be shown on mouse over on you <p>

There are may tool-tip of jquery available which you can use.

  1. http://jqueryui.com/tooltip/#default
  2. http://jquerytools.org/documentation/tooltip/

Upvotes: 0

Related Questions