Click here to Skip to main content
15,904,494 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to control the number of text displayed in a label in a datalist???
can anyone suggest the code for this problem...if length of description exceeds 100 characters and a "show more" link to appear ("show less" is not necessary). Once "Show more" is clicked the full description should appear on the next page...


thank uu..
Posted
Updated 25-Feb-14 0:19am
v2
Comments
Kornfeld Eliyahu Peter 25-Feb-14 6:20am    
Have you done anything so far? Show some effort (code or searching)! As is it ain't a question...
jaishr 25-Feb-14 6:25am    
<asp:DataList ID="DataList1" runat="server" Width="627px" BorderColor="Black"
BorderStyle="Solid" BorderWidth="1px">
<alternatingitemstyle bordercolor="Black" backcolor="#F7F7F7">
<itemstyle forecolor="Black">
<itemtemplate>
<tr>
<td>
<asp:Image ID="imgEmp" runat="server" Width="120px" Height="100px" ImageUrl='<%#Eval("photo") %>' style="padding-left:40px"/>
<asp:Label runat="server" CssClass="ShortDesc" Text='<%# Eval("news")%>' id="Label2" Font-Names="Trebuchet MS" Font-Size="Small" style="height: 138px; width: 400px" >

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/sub editor/subeditor_editor.aspx" Text="Read more..." ForeColor="red" />
</td>
</tr>



i tried this, but not helped me:
Text='<%# Eval("news").ToString().SubString(0,Math.Min(200,Eval("news").ToString().Length)) %>'
jaishr 25-Feb-14 8:04am    
tried these too..
Eval("news").SubString(0,100)

word-break: break-all; word-wrap: break-word;
but 2.1 doesn't contain these properties
thank uuu...

1 solution

Use Item data bound event of data list .
Try to do some thing like this code.
C#
protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e) {
   if (e.Item.ItemType == ListItemType.Item) {
        Label lbl =(Label)e.Item.FindControl("panelPostDetails").FindControl("lblMorePictures");
        string tempString = lbl.Text;
        if(tempstring.length>100)
        {
          tempString=tempstring.subString(0,100);
          tempstring=tempstring+"...";
          lbl.Text= tempstring;
        }
   }
}

I have written this code as text. So if there is any syntax problem, please correct it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900