Please explain HtmlTableRow - does not make sense

  • Thread starter Thread starter JP
  • Start date Start date
J

JP

I have the below code cycle through an HTML table control that is running
server side. I have it basically search for an attribute in the TR tag I
called “right†and if the attribute is present then the visibility of the TR
tag is set to the value of the variable in question.

<table width="100%" id="tableProfile" runat="server">
<tr right=â€IsTechâ€>
<td>
Only visible if IsTech True
</td>
</tr>
<tr right=â€IsAdminâ€>
<td>
Only visible if IsAdmin True
</td>
</tr>
<tr>
<td>
Notice no attribute here – should be visible
</td>
</tr>
</table>

However, it’s still hiding rows that don’t even have the attribute. I’ve
checked to make sure there isn’t an orphaned tag or anything. It hides the
first row as expected but on the next row it hides all rows

On top of that the HtmlTable.Rows collection says there are only 12 rows in
the table, but there are more then 20. I cannot find a rhyme or reason to the
behavior .NET is producing. Sometimes it says the attribute but on the next
row is say there is not attribute.

Even if I adding the visible rows to a new object:

HtmlTable NewTable = new HtmlTable
NewTable.Rows.Add(profileTable)

Then it says the enumerator of profile table has changed. How is that
possible? I didn’t add anything to profile table. I added it to a separate
copy

private void RemoveOptions(bool IsTech, bool IsAdmin, bool IsSysAdmin)
{
foreach (HtmlTableRow profileRow in ((HtmlTable)tableProfile).Rows)
{
if (profileRow.Attributes["right"] != null)
{
profileRow.Visible = profileRow.Attributes["right"].Contains("IsSys") ?
IsSysAdmin : false;
profileRow.Visible =
profileRow.Attributes["right"].Contains("IsAdmin") ? IsAdmin : false;
profileRow.Visible =
profileRow.Attributes["right"].Contains("IsTech") ? IsTech : false;
}
else
{
profileRow.Visible = true;
}
}
}
 
You are using a standard HTML table and so, it can't be accessed via server
code. If you use the ASP.NET Table Server Control, you'd be able to. Or,
you could just add runat="server" to the element in question and ad an ID to
it. Then, you'd be able to access it as an object on the server.

-Scott
 
Back
Top