DataRepeater and Attributes of non asp html control

Throwman

New member
Joined
Oct 22, 2015
Messages
2
Programming Experience
10+
Here's the scenario.

I have a Menu it's one level deep. There are 4 parent level entries, each with several children. This is a vertical menu that will appear on the left side of a web page. I'm reading in 2 values from the querystring, one of them to determine which parent menu item to expand. What I've done works for 2, 3, and 4, but it won't open for 1, as illustrated in my attachments. I have stepped through the code and the values all look correct when stepping through, but when rendered, the "in" is always missing, and the aria-expanded is always false for #1.

Any ideas?


1. The menu is loaded using a DataRepeater, on its ItemDataBound event,

private int SpecialCssCount = 1;
protected string ExpandedNode = Request.QueryString["x"];

protected void RptMainNavItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
var item = (Item)e.Item.DataItem;
var linkMainNavItem = e.Item.FindControl("linkMainNavItem") as HyperLink;


if (item != null && linkMainNavItem != null)
{
if (SpecialCssCount.ToString() == ExpandedNode) { Expanded = true; } else { Expanded = false; }


SpecialCssCount += 1;

2. On the front end I'm using some code blocks in a non-asp <ul>

<ul id='<%# "collapse" + NumberToText(Container.ItemIndex + 1).Trim()%>' class="panel-collapse collapse <%# Expanded ? "in":string.Empty %>" aria-expanded="<%# Expanded.ToString().ToLower() %>" role="tabpanel" >

Working for 2:
aaExample1.png

Not working for 1:
aaExample2.png
 
Updated code, the preceding was left over from a test. This is the more accurate code. With this code (1 opens 2, 2 opens 3, 3 opens 4, 4 opens none)

private int SpecialCssCount = 0;
protected string ExpandedNode = Request.QueryString["x"];

protected void RptMainNavItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
var item = (Item)e.Item.DataItem;
var linkMainNavItem = e.Item.FindControl("linkMainNavItem") as HyperLink;


if (item != null && linkMainNavItem != null)
{

SpecialCssCount++;
if (SpecialCssCount.ToString() == ExpandedNode) { Expanded = true; } else { Expanded = false; }

2. On the front end I'm using some code blocks in a non-asp <ul>

<ul id='<%# "collapse" + NumberToText(Container.ItemIndex + 1).Trim()%>' class="panel-collapse collapse <%# Expanded ? "in":string.Empty %>" aria-expanded="<%# Expanded.ToString().ToLower() %>" role="tabpanel" >
 
Back
Top Bottom