2012-02-02 45 views
0

大家好我使用下面的代碼添加圖像到label文本圖像的寬度是否有可能設置高度和被分配到一個標籤動態

lblPopUp.Text = "<img src='Popup(Images)/notfound.png' />&nbsp;&nbsp;&nbsp;&nbsp; Access Denied,Contact Administrator";

這導致了我如下的時候加載

enter image description here

是否有可能改變一些如下,這樣的文字和圖像看起來應該類似於什麼

enter image description here

回答

2

如果我正確地理解了你,一個小小的字符串操作應該能夠實現你想要的。

代碼:

lblPopup.Text = "<img src='Popup(Images)/notfound.png' />&nbsp;&nbsp;&nbsp;&nbsp; Access Denied,Contact Administrator"; 
String strInsertStyle = " style=\"height: 100px; width: 100px;\""; 
int intInsertPoint = lblPopup.Text.IndexOf("<img") + 4; 
lblPopup.Text = lblPopup.Text.Substring(0, intInsertPoint) + strInsertStyle + lblPopup.Text.Substring(intInsertPoint); 

編輯: 我也假設你的意思是你想在以後添加的高度/寬度,與jadarnel27的答案,否則去。

1

您可以設置高度和寬度與<img>標籤的heightwidth屬性:

lblPopUp.Text = "<img src='Popup(Images)/notfound.png' height='50px' width='50px' />&nbsp;&nbsp;&nbsp;&nbsp; Access Denied,Contact Administrator"; 

或者,你可以使用style屬性:

lblPopUp.Text = "<img src='Popup(Images)/notfound.png' style='height:50px; width:50px;' />&nbsp;&nbsp;&nbsp;&nbsp; Access Denied,Contact Administrator"; 


還有一件事:我會 強烈建議不要使用所有這些 &nbsp來確保您的對齊方式正確。在您的 <img>標籤上放置一些 padding-right將會更容易和更穩定。

+0

爲jquery的缺席事先道歉;-) – jadarnel27 2012-02-02 16:39:50