I have a table that is created in ASP.NET C # code. The table has several levels of groupings, and when I create rows for the outermost grouping, I add a custom attribute as follows:
foreach (Table2Row row in Table2Data) { // skipping a bunch of irrelevent stuff ... tr_group.Attributes.Add("RowsToToggle", String.Format(".InnerRowGroupId_{0}", row.GroupHeaderId)); ... }
The attribute is the name of the CSS class for the inner level strings that I would like to switch. When the user clicks on the outer level row, I would like to call the jQuery Toggle function for all the inner level rows that match the user attribute.
To achieve this effect, I attached the onclick event to the header lines with the following script in the aspx file:
var tableId = '<%= Table2MainTable.ClientID %>'; $(document).ready(function () { var table = document.getElementById(tableId); var groupRows = table.getElementsByClassName("Table2GroupHeaderRow"); for (i = 0; i < groupRows.length; i++) { table.groupRows[i].onclick = function () { ToggleOnRowClick(table.rows[i]); } } }); function ToggleOnRowClick(row) { var r = $('#' + row.id); var innerRows = r.attr('RowsToToggle'); $(innerRows ).toggle(); }
So, clicking anywhere on the title bar should call the ToggleOnRowClick function, which then should switch the rowset below it using the custom RowsToToggle attribute.
When I set a breakpoint (FireBug) in the ToggleOnRow function, the r variable seems to point to the correct object. However, innerRows does not get set, but instead remains null. So am I setting the user attribute incorrectly in ASP.NET or reading it incorrectly in jQuery?
source share