Note that there are some explanatory texts on larger screens.

plurals
  1. POslidetoggle for gridview in dynamically generated "expandable" rows
    primarykey
    data
    text
    <p>Well, I have a situation where I need to provide a slidetoggle effect for my gridview's dynamically generated rows. I use a javascript + pagemethod to achieve the auto generation.</p> <p>This is my ItemTemplate for the gridview</p> <pre><code> &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;a href="javascript:void"&gt; &lt;asp:Image ID="imgExpandCollapse" runat="server" ImageUrl="~/Images/expand.png" onclick='ShowDetails(this);' ToolTip="Toggle"/&gt;&lt;/a&gt; &lt;asp:Label ID="lblUID" Style="display: none" runat="server" Text='&lt;%# Eval("UID") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; </code></pre> <p>I use the following javascript to generate the rows dynamically by calling a web method.</p> <pre><code>function ShowDetails(ImgObj) { if (ImgObj.src.toLowerCase().indexOf("expand") != -1) { if (document.getElementById(ImgObj.id.replace("imgExpandCollapse", "grdRowDetails")) != null) { document.getElementById(ImgObj.id.replace("imgExpandCollapse", "grdRowDetails")).style.display = ""; } else { var newTr = document.createElement("tr"); newTd = document.createElement("td"); var UID = document.getElementById(ImgObj.id.replace("imgExpandCollapse", "lblUID")).innerHTML; newTd.setAttribute("id", ImgObj.id.replace("imgExpandCollapse", "grdRowDetails")); newTd.setAttribute("colspan", "7"); newTd.setAttribute("Style", "padding:0 0 0 0"); newTd.innerHTML = "&lt;div class='centerAlign'&gt;&lt;img src='../Images/loading.gif'/&gt;&lt;/div&gt;"; PageMethods.GetLogResult(UID, OnSucceeded, OnFailed,newTd); newTr.appendChild(newTd); jQuery('#' + ImgObj.id.replace("imgExpandCollapse", "grdRow")).after(newTr); } ImgObj.src = "../Images/collapse.png"; } else { if (document.getElementById(ImgObj.id.replace("imgExpandCollapse", "grdRowDetails")) != null) { document.getElementById(ImgObj.id.replace("imgExpandCollapse", "grdRowDetails")).style.display = "none"; } ImgObj.src = "../Images/expand.png"; } } function OnSucceeded(result, newTd) { newTd.innerHTML = result; } function OnFailed(error) { alert(error.id); } </code></pre> <p>Now the issue of using a Slidetoggle() is that these rows are autogenerated and they have different IDs. Now if somebody could help me out with this, I would be grateful. Thanks.</p> <p>EDIT: Apparently, I was trying to "slide" a table row, which aint supported for slidetoggle in Jquery. I changed the code and it worked :)</p> <pre><code>function ShowDetails(ImgObj) { if (ImgObj.src.toLowerCase().indexOf("expand") != -1) { if (document.getElementById(ImgObj.id.replace("imgExpandCollapse", "grdRowDetails")) != null) { $("#" + ImgObj.id.replace("imgExpandCollapse", "grdRowDetails")).slideToggle(); } else { var newTr = document.createElement("tr"); newTd = document.createElement("td"); newDiv = document.createElement("div"); var UID = document.getElementById(ImgObj.id.replace("imgExpandCollapse", "lblUID")).innerHTML; newTd.setAttribute("colspan", "7"); newTd.setAttribute("Style", "padding:0 0 0 0"); newDiv.setAttribute("id", ImgObj.id.replace("imgExpandCollapse", "grdRowDetails")); newDiv.setAttribute("style", "text-align:center"); newDiv.innerHTML = "&lt;img src='../Images/loading.gif'/&gt;"; PageMethods.GetLogResult(UID, OnSucceeded, OnFailed, newDiv); newTd.appendChild(newDiv); newTr.appendChild(newTd); jQuery('#' + ImgObj.id.replace("imgExpandCollapse", "grdRow")).after(newTr); $("#" + newDiv.id).show(); } ImgObj.src = "../Images/collapse.png"; } else { if (document.getElementById(ImgObj.id.replace("imgExpandCollapse", "grdRowDetails")) != null) { $("#" + ImgObj.id.replace("imgExpandCollapse", "grdRowDetails")).slideToggle(); } ImgObj.src = "../Images/expand.png"; } } function OnSucceeded(result, newDiv) { newDiv.innerHTML = result; } function OnFailed(error) { alert(error.id); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload