Limit asp:label Databinder.Eval characters displayed

J

John

Hello
I want to use the same data string (memo) to populate a "summary" asplabel. After the summary there would be a + "..." and a "see more..." link to the "complete" string contents - for the summary (e.g. aspLabel ID="lblSName" text=Databinder.Eval(Container.Dataitem,"Description") Runat="server"aspLabel) I need to limit the number of characters displayed.

Any ideas?
Thanks
John

From http://www.developmentnow.com/g/8_2004_11_0_17_0/dotnet-framework-aspnet.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
 
G

Guest

I would try in this line...

1) Bind the Memo to 2 Lables . Label1 will be the summary and Label2 will be
the full text.
2) Use javascript to hide Label1 and show Label2 onmouseover / onclick on
"+...See more" on Label1. Hide Label2 and Show Label1 onmouseout of Label2

to trim the text to summary , implement a function in code behind

protected string TrimMemo(string Memo)
{
string Summary = Memo.SubString(1,100);
Summary += "<A HREF='javascript:ShowL2HideL1();' > +...See more </A>"
return(Summary);
}

Then call it during databinding.

aspLabel ID="lblSName"
text=TrimMemo(Databinder.Eval(Container.Dataitem,"Description"))
Runat="server"aspLabel


HTH
 
Joined
Jul 23, 2009
Messages
1
Reaction score
0
substring index out of range? this will cover your nuts

<asp:TemplateField HeaderText="Note" ItemStyle-Width="110">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"VoucherNote").ToString().Length > 20 ?
DataBinder.Eval(Container.DataItem, "VoucherNote").ToString().Substring(0,20) :
DataBinder.Eval(Container.DataItem,"VoucherNote").ToString().Substring(0,DataBinder.Eval(Container.DataItem,"VoucherNote").ToString().Length)%>
</ItemTemplate>
</asp:TemplateField>
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top