change classes based on html without using javascript?
I am not sure if is it possible or not but I have to change some classes of <li>
tag which I am getting from ascx file.Now the condition which li to change or no is based on html that I am producing with the help of xsl(written in code behind).
I know i can do this with the help of Javascript. But what if I don't wanna use javascript and want to do it wth the help of code behind itself.Is this possible let me explain this with the example also
<li>A</li>
<li>B</li>
<li>C</li>
-----
----
I am getting A,B,C from the user control using Datagrid for it. now In this user control I have xslt and from this xslt I am getting html A,B.... and I want to change classes of li tag of A and B to sth else now.Can I do it withot using java开发者_开发知识库cript. I want to write sth in my codebehind to acheive this...Can anyone tell me how is it possible?? any idea....
As you said, this has to be done in the code-behind if you aren't willing to use javascript on the client-side.
There are many ways to do this in code. Your best option may be to create generic html controls, which you can apply classes to.
If you're processing a li element, you can create a list item generic html control and apply a class to it via:
//create an unordered list
HtmlGenericControl myList = new HtmlGenericControl("ul");
//create the list item
HtmlGenericControl myListItem = new HtmlGenericControl("li");
myListItem.InnerText = "A"; //you can get/set the li item contents using this property
//set the class here
myListItem.Attributes["class"] = "someClassName";
//add the list item to the list, and the list to the control set of your page, usercontrol,etc.
myList.Controls.Add(myListItem);
this.Controls.Add(myList);
Hope this helps.
精彩评论