【问题标题】:Problem adding attributes to Asp ListBox's ListItems in code behind在后面的代码中向 Asp ListBox List Items 添加属性时出现问题
【发布时间】:2011-08-06 03:36:12
【问题描述】:

我在aspx页面上的ListBox如下:-

 <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");

【问题讨论】:

    标签: c# asp.net css


    【解决方案1】:

    我认为你应该使用 CssClass 属性或设置 'class' 属性而不是样式,因为如果你设置多个样式,实际上你每次都会覆盖样式。

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

    在后面的代码中设置类: Adding css class through aspx code behind

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-14
      • 2011-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-15
      • 2012-06-14
      • 1970-01-01
      相关资源
      最近更新 更多