Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get my ASP table control to show/hide? (not as simple as it sounds)
    primarykey
    data
    text
    <p>Alright, I'm fairly new to ASP.NET, but I think I understand what's going on,. I've been tasked with building reports in them. So far, I've got everything down except for this one issue.</p> <p>I use a Repeater that's databound to a DataRowCollection and programatically build a table through that. I have something similar to:</p> <pre><code>Private Sub SubAcctGrid_OnItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then Dim currentrow = TryCast(e.Item.DataItem, DataRow) Dim acctSummaryTable = New Table With {.ID = "acctSummary" &amp; e.Item.ItemIndex, .CssClass = "minisub_acct_table"} Dim drillDownTable = New Table With {.ID = "drillDownTable" &amp; e.Item.ItemIndex, .CssClass = "drilldown_table"} ' Build both tables here acctSummaryTable.Rows(1).Cells(0).Attributes.Add("onclick", String.Format("displayDetailTable('{0}')", drillDownTable.ID)) acctSummaryTable.Rows(1).Cells(1).Attributes.Add("onclick", String.Format("displayDetailTable('{0}')", drillDownTable.ID)) e.Item.Controls.Add(acctSummaryTable) e.Item.Controls.Add(drillDownTable) End If End Sub </code></pre> <p>I have a Javascript function that takes in the element ID and hides or shows the table:</p> <pre><code>function displayDetailTable(tableID) { var table = document.getElementById(tableID) if (table.style.display == "none") { table.style.display = "table"; } else { table.style.display = "none"; } } </code></pre> <p>I can't, for the life of me, pass in the correct element ID, though. From what I understand, ASP.NET transforms the ID I assign into some huge long ID for the sake of uniqueness. For example, I assign a table with the ID 'drillDownTable0' and it spits out 'ctl00_drillDownTable0' in the HTML markup. It worked the first time around, but then the Repeater gets binded to a new row and then I get 'ctl01_drillDownTable0' so on and so forth.</p> <p>I've tried the ClientID, ID, and UniqueID where I add the attributes to the Cells in the code above and they don't do what I need to.</p> <p>Is there any way I can get that ID and pass it to the Javascript function? Or I guess a better question is: When are the IDs generated and can I get to them before the page is rendered in HTML?</p>
    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