我怎样才能改变我的课程 [英] How can I change I class

查看:58
本文介绍了我怎样才能改变我的课程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改< i class =ico i-medium>< / i> to< i class =ico i-easy>< / i>



我怎么能这样做c#代码?



 <   asp:DataList     ID   =  dlTarifler    runat   =  server    RepeatColumns   =  3    DataKeyField   =  tarifID    EditItemStyle-BackColor   = 透明    ItemStyle-BackColor   = 透明 >  
< ItemTemplate >
< div class = 条目三分之一哇fadeInLeft >
< 数据 >
< img src =' <% #Eval( Resim1)%>' < span class =code-attribute> alt = / >
< figcaption > < a href = recipe.html?tno = +' <%#Eval(tarifID) & gt; '> < span > Tarifi Gor < / span > < / a > < / figcaption >
< / figure >
< div class = < span class =code-keyword> container >
& h2 > < a href = recipe.html?tno = +'<%# Eval(tarifID) > ; '> <% #Eval( ad)%> < / a > < / h2 >
< div class = actions >
< div >
< div class = 难度 > < i id = Zorlu < span class =code-attribute> runat = 服务器 class = ico i-medium > ; < a href = > <% #Eval( Zorluk)%> < / a > < / div >
< div < SP class =code-attribute> class = > < a href = > < span class =code-pagedirective><% #Eval( Populerlik )%> < / a > < / div >
< div <温泉n class =code-attribute> class = comments > < a href = recipe.html#comments > < ;% #Eval( Yorumlar)%> < / a > < / div >
< / div >
< / div >
< / div >
< / div >
< / ItemTemplate >
< / asp:DataList >





我的尝试:



给id和调用c#代码部分

但我不能调用id

解决方案

那里不是您粘贴的代码中的任何i元素。要从服务器代码修改它,你需要添加runat =server



 < ;   i     runat  < span class =code-keyword> =  server    id   =  myI >  Hello <   / i  >  





服务器代码;



< pre lang =c#> myI.Attributes [ class] = ico i-easy;





如果元素不在页面上但在容器中,则需要查找控制得到它;



 HtmlGenericControl myI =(HtmlGenericControl)parentControl.FindControl(   myI); 


要回答这个问题,您需要了解如何Web工作原理。



你不要在C#中改变任何东西;这不是事情的运作方式。服务器端代码的整个操作是响应HTTP请求并创建HTTP响应。如果这是HTML,则代码会创建整页。当然,在回调之后,您可以生成具有不同上下文的HTML。换句话说,明确地做或者使CSS 的值成为ASP.NET表达式(<%...%> )。除此之外,您还可以使用Ajax通过HTTP请求/响应交换任意信息。整个ASP.NET都是关于这个方案的。



呈现页面后,页面内容保持不变,或者可以通过JavaScript在客户端修改。您可以在ASP.NET中编写静态JavaScript或注册客户端脚本。这是脚本如何修改元素的CSS类:

Element.className - Web API | MDN [ ^ ],

Element.classList - Web APIs | MDN [ ^ ]。



如果你在客户端进行,更改将立即呈现,不会使用任何流量,等等。



-SA


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: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") %>'> <span>Tarifi Gor</span></a></figcaption>
    </figure>
    <div class="container">
        <h2><a href="recipe.html?tno="+'<%#Eval("tarifID") %>'><%#Eval("ad") %></a></h2>
        <div class="actions">
            <div>
                <div class="difficulty" ><i id="Zorlu"  runat="server" class="ico i-medium"><a href="#"><%#Eval("Zorluk") %></a></div>
                <div class="likes"><a href="#"><%#Eval("Populerlik") %></a></div>
                <div class="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

解决方案

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

<i runat="server" id="myI">Hello</i>



Server code;

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;

HtmlGenericControl myI = (HtmlGenericControl)parentControl.FindControl("myI");


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


这篇关于我怎样才能改变我的课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆