2010-11-26 53 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的工作。