如何获取HtmlGenericControl的属性值?

Any*_*are 5 html c# asp.net htmlgenericcontrol

我这样创建HtmlGenericControl:

HtmlGenericControl inner_li = new HtmlGenericControl("li");
inner_li.Attributes.Add("style", "list-style-type: none");
Run Code Online (Sandbox Code Playgroud)

我怎样才能得到这个attribue(style)的价值.

Ale*_*lex 9

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

var style = inner_li.Attributes["style"];
Run Code Online (Sandbox Code Playgroud)

只是旁注:在处理样式时,最好使用HtmlControl.Style属性:

inner_li.Style[HtmlTextWriterStyle.ListStyleType] = "none";
Run Code Online (Sandbox Code Playgroud)