In the following legend the text is many characters (long Question) ..What I want is that only first 10 characters of the question be displayed and then dots..something like :-
What is asp.net? What do yo...
How do I do this?
<fieldset style="padding: 10px;"> 开发者_如何学JAVA
<legend style="padding: 5px;">
<b>
Question:
<%#Eval("Question")%>
</b>
</legend>
</fieldset>
In the code behind where you expose the Question
property, I'd also expose a TruncatedQuestion
like so:
public string TruncatedQuestion
{
get
{
if (Question.Length > 10)
return Question.Substring(0,10) + "...";
else
return Question;
}
}
Then replace <%#Eval("Question")%>
in your code with <%#Eval("TruncatedQuestion")%>
You can perform this via CSS with some proper markup:
HTML:
<fieldset>
<legend>Question: <% #Eval("Question") %></legend>
</fieldset>
CSS:
fieldset
{
padding: 10px;
}
legend
{
padding: 5px;
width: 10em;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
text-overflow:
ellipsis
will work in IE7, Safari and Mozilla.
精彩评论