2010-11-26 59 views
1

在下面的图例中的文本是许多字符(长的问题)..What我想要的是显示问题的只有前10个字符,然后dots..something,如: -约传说标签

是什么asp.net?什么哟...

我该怎么做?

<fieldset style="padding: 10px;">       
    <legend style="padding: 5px;"> 
    <b>  
     Question:&nbsp; &nbsp;  
     <%#Eval("Question")%>  
    </b> 
    </legend>      
</fieldset> 
+1

了解如何正确格式化代码和标记,并开始做!请 – abatishchev 2010-11-26 13:07:03

回答

4

在你暴露Question属性后面的代码,我还暴露出TruncatedQuestion像这样:

public string TruncatedQuestion 
{ 
    get 
    { 
     if (Question.Length > 10) 
      return Question.Substring(0,10) + "..."; 
     else 
      return Question; 
    } 
} 

然后用<%#Eval("TruncatedQuestion")%>

+0

我需要在我的代码中定义这个TruncatedQuestion字符串?究竟在哪里? – Serenity 2010-11-26 19:57:37

+0

目前定义的问题在哪里?在旁边。 – 2010-11-27 10:49:36

1

可以进行替换<%#Eval("Question")%>在你的代码这通过CSS与一些适当的标记:

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将在IE7,Safari浏览器和Mozilla的工作。