问题
I create HtmlGenericControl
like this :
HtmlGenericControl inner_li = new HtmlGenericControl("li");
inner_li.Attributes.Add("style", "list-style-type: none");
How can i get the value of this attribue(style
).
回答1:
You can do it using indexer:
var style = inner_li.Attributes["style"];
Just a side note: when dealing with styles it's better to use HtmlControl.Style property:
inner_li.Style[HtmlTextWriterStyle.ListStyleType] = "none";
回答2:
The Attributes property is name value collection. So you can do
string tempstr = inner_li.Attributes["style"]
.
See the msdn doc.
回答3:
You can get the value using the below statement
string myvalue= inner_li.Attributes["style"];
来源:https://stackoverflow.com/questions/9496037/how-can-i-get-the-attribute-value-of-htmlgenericcontrol