Senthil Natarajan Senthil Natarajan - 1 year ago 81
C# Question

Add mulitple inline style from code behind

I know i can add style from code behind this way

imgStory1.Style.Add("border", "none");
imgStory1.Style.Add("outline", "none");
imgStory1.Style.Add("height", "auto !important");

and so on, but I would like to do it in a much efficient way if possible. Please note I cannot do this through CSS it has to be inline styling.

Answer Source

Here is a way to write it in one line

imgStory1.Attributes.Add("style", "display: center;border: none; outline: none");

for overwriting existing

imgStory1.Attributes["style"] = "display: center;border: none; outline: none";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download