Click here to Skip to main content
15,908,254 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i want to change <i class="ico i-medium"></i> to <i class="ico i-easy"></i>

how can i do this c# code?

ASP.NET
<asp:DataList ID="dlTarifler" runat="server" RepeatColumns="3" DataKeyField="tarifID" EditItemStyle-BackColor="Transparent" ItemStyle-BackColor="Transparent">
    <ItemTemplate>
       <div class="entry one-third wow fadeInLeft">
    <figure>
        <img src='<%#Eval("Resim1") %>' alt="" />
        <figcaption><a href="recipe.html?tno="+'<%#Eval("tarifID") %>'><a href="#"><%#Eval("Populerlik") %></a></div>
                <div class="comments">^__i class="ico i-comments"><a href="recipe.html#comments"><%#Eval("Yorumlar") %></a></div>
            </div>
        </div>
    </div>
</div>
    </ItemTemplate>
</asp:DataList>


What I have tried:

giving id and calling c# code part
but i cant call the id
Posted
Updated 27-May-16 3:28am
v3
Comments
Karthik_Mahalingam 27-May-16 9:54am    
post the code where you are assigning the class <i class="ico i-medium" abp="490"></i>

There isn't any i element in the code you have pasted. To amend it from server code you need to add runat="server"

ASP.NET
<i runat="server" id="myI">Hello</i>


Server code;

C#
myI.Attributes["class"] = "ico i-easy";


If the element isn't on the page but in a container you'll need FindControl to get it;

C#
HtmlGenericControl myI = (HtmlGenericControl)parentControl.FindControl("myI");
 
Share this answer
 
v4
Comments
Richard Deeming 27-May-16 9:32am    
+5, but the question said <i>, not <li>. :)
F-ES Sitecore 27-May-16 9:32am    
I know :o I was amending it when you posted :D
Member 10525430 27-May-16 9:36am    
its return null
F-ES Sitecore 27-May-16 10:00am    
If the element is inside a template control like a datalist etc you need to find it via the bound event as the data is binding, or by going through the rows after the element has been bound

http://forums.asp.net/t/1963903.aspx?Finding+controls
To answer this question, you need to understand how Web works in general.

You don't "change" anything in C#; this is not how things work. The whole operation of the server-side code is to respond to HTTP request and create an HTTP response. If this is HTML, your code creates whole page. Naturally, after the callback you can generate HTML with different context. In other words, do it explicitly or make the value of the CSS class an ASP.NET expression (<% … %>). In addition to that, you can exchange arbitrary information via HTTP request/response using Ajax. Whole ASP.NET is all about this scheme.

After the page is rendered, the page content remains the same or can be modified on client side via JavaScript. You can write a static JavaScript or register client script in ASP.NET. This is how a script can modify a CSS classes of an element:
Element.className — Web APIs | MDN[^],
Element.classList — Web APIs | MDN[^].

If you do in on client side, the changes will be rendered immediately, no traffic will be used, and so on.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900