开发者

Problem adding attributes to Asp ListBox's ListItems in code behind

开发者 https://www.devze.com 2023-02-25 12:42 出处:网络
My ListBox on aspx page is as follows:- <asp:ListBox ID=\"ddlItems\" runat=\"server\" Style=\"padding: 2px; width: 210px; height:200px;\">

My ListBox on aspx page is as follows:-

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

I am adding BackGround Image to my List items as

follows in code behind and its working perfectly:-

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

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

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

Now I have tried many things but I cant get to make

the list items' font bold and White in color. Also

how can I increase the height of these list items

and hence the font size?

I have tried the following but its' not working:-

  myListItem.Attributes.Add("ForeColor", "White");
  myListItem.Attributes.Add("style", "fo开发者_开发百科nt-weight:bold");


I think you should use CssClass property or set 'class' attribute instead of style, because if you're setting multiple styles, you are in fact overwriting style each time.

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

setting class in code behind: Adding css class through aspx code behind

0

精彩评论

暂无评论...
验证码 换一张
取 消