简体   繁体   English

使用Javascript在Listview ASP.NET中查看隐藏的div标记

[英]Using Javascript to view a hidden div tag in Listview ASP.NET

 <ItemTemplate> <tr bgcolor="#efefef"> <td width="10%"> <asp:LinkButton ID="btnShowRoles" runat="server"> <asp:Image ID="viewRoles" ImageUrl="/images/pointer-down.gif" runat="server" /></asp:LinkButton> </td> <td width="50%" align="left"> <font face="verdana" size="1"> <asp:Label runat="server" ID="lblParameter"><%#Eval("Name") %></asp:Label> </font> </td> <td width="10%" align="center"> <font face="verdana" size="1"> <asp:Label runat="server" ID="lblType"><%#Eval("Type.Name")%></asp:Label> </font> </td> <td width="10%" align="center"> <font face="verdana" size="1"> <asp:Label runat="server" ID="lblRequired"><%#Eval("isGlobal") %></asp:Label> </font> </td> <td width="20%" align="center"> <font face="verdana" size="1"><a href='<%#GetRedirectionURL(Eval("ID")) %>'>VIEW</a> </font> </td> </tr> <tr> <td> <div align="left" class="ShowRoles"> <asp:Label ID="Label3" runat="server">GROUPS:</asp:Label> <asp:Label ID="Label4" runat="server"><%#Eval("MarjorieRoles") %></asp:Label> </div> </td> </tr> 

This is the code for my ItemTemplate in a ListView. 这是ListView中我的ItemTemplate的代码。 I want the linkbutton in the first to show the fields whenever clicked. 我希望第一个链接按钮在单击时显示字段。 I am new to javascript and have absolutely no idea how to go about it. 我是javascript新手,绝对不知道该怎么做。 Any help would be appreciated. 任何帮助,将不胜感激。 Thanks 谢谢

This is not a specific question, but I can give you a few pointers to help you get started. 这不是一个具体的问题,但是我可以给您一些指导,以帮助您入门。

1) In HTML, each element on your page is marked with an id attribute. 1)在HTML中,页面上的每个元素都标记有id属性。 In JavaScript, you can use the function document.getElementById to get an element by its id. 在JavaScript中,您可以使用函数document.getElementById通过其ID获取元素。 You can also use an element's class with document.getElementsByClass . 您还可以将元素的类与document.getElementsByClass

2) And this is very important. 2) 非常重要。 Any time you add a server-side control to your page, it will be assigned an id in the resulting HTML that may be completely different from the ID you specify in the mark-up. 每当您在页面上添加服务器端控件时,都会在结果HTML中为其分配一个ID,该ID可能与您在标记中指定的ID完全不同。 In ASP.net, you can get the client-side id by writing <%= elementId.ClientID %> . 在ASP.net中,可以通过编写<%= elementId.ClientID %>来获取客户端ID。

3) A library like jQuery may be very helpful in simplifying your development. 3)像jQuery这样的库可能对简化您的开发非常有帮助。 With jQuery, you would use the $.click function to attach an event to the buttons click event. 使用jQuery,您可以使用$.click函数将事件附加到按钮click事件。 You can use the $.show function to make a hidden element appear. 您可以使用$.show函数使隐藏的元素出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM