2011-04-15 21 views
0

我的列表框如下: -問題aspx頁面上添加屬性爲Asp ListBox的listItems中的代碼背後

<asp:ListBox ID="ddlItems" runat="server" Style="padding: 2px; width: 210px; height:200px;"> 
    </asp:ListBox> 

我添加背景圖片到我的列表項爲

跟隨後面的代碼及其完美的工作: -

myListItem.Attributes.Add("style", "background-image:url(" + "'www.mysite.com/" + 

"images/Gradient/" + ds.Tables[0].Rows[iGroups] 

["Backgroundimage"].ToString() + "');"); 

現在我已經嘗試了很多事情,但我不能讓做

列表項的字體加粗和白色。此外

我怎麼能增加這些列表項

,因此字體大小的高度?

我曾嘗試以下,但它的不工作: -

myListItem.Attributes.Add("ForeColor", "White"); 
    myListItem.Attributes.Add("style", "font-weight:bold"); 

回答

2

我認爲你應該使用CssClass屬性或設置‘類’屬性而不是風格,因爲如果你設置多個樣式,你實際上每次都是覆蓋樣式。

的CssClass: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.cssclass.aspx

設置類在後面的代碼: Adding css class through aspx code behind

+0

你是對的!這是覆蓋。謝謝! :D – Infinity 2011-04-15 08:33:06

+0

很高興幫助:) – Robert 2011-04-15 08:33:46

相關問題