i have a grid with an image column, i want to change images based on data source.
if data field for a row is 2 then image will be *.gif and if it is 3 then will be different so it is not fixed that which type of images we will have so i want to do “if..else” on css because in that case we can easily change images on css. i don’t want code on code behind file.
i have a grid with an image column, i want to change images based
Share
CSS does not have any programming constructs such as constants or if / else. There are however several extension to CSS that provide this:
xCSS it can nest child elements.
Then there’s LESS, it’s written in Ruby so you need that installed (as far as I understand, I haven’t used it myself yet) but it’s perfectly suitable for editing CSS in any environment. Check the “nested rules” section on the front page.
A simpler solution to your problem is to keep your CSS static, but change the CSS class of your element based on your condition.
See the following page:
http://www.w3schools.com/ASPNET/prop_webcontrol_style_cssclass.asp
e.g. the following button has its style set via the CssClass property:
You can of course set this in code-behind based on some logic.