【问题标题】:How can i get the attribute value of HtmlGenericControl?如何获取 HtmlGenericControl 的属性值?
【发布时间】:2012-02-29 08:51:30
【问题描述】:

我这样创建HtmlGenericControl

HtmlGenericControl inner_li = new HtmlGenericControl("li");
inner_li.Attributes.Add("style", "list-style-type: none");

我怎样才能得到这个属性的值(style)。

【问题讨论】:

    标签: c# asp.net html htmlgenericcontrol


    【解决方案1】:

    您可以使用索引器来做到这一点:

    var style = inner_li.Attributes["style"];
    

    附注:处理样式时最好使用HtmlControl.Style 属性:

    inner_li.Style[HtmlTextWriterStyle.ListStyleType] = "none";
    

    【讨论】:

      【解决方案2】:

      Attributes 属性是名称值集合。所以你可以做 string tempstr = inner_li.Attributes["style"]

      请参阅msdn doc

      【讨论】:

        【解决方案3】:

        您可以使用以下语句获取值

        string myvalue= inner_li.Attributes["style"];
        

        【讨论】:

          猜你喜欢
          • 2015-03-10
          • 1970-01-01
          • 2013-05-02
          • 1970-01-01
          • 2023-03-17
          • 2011-06-11
          • 2018-10-31
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多