How can i get the attribute value of HtmlGenericControl?

北慕城南 提交于 2019-12-10 14:16:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!