Reputation: 669
I'm trying to build a list from a datatable, and the function also needs to add group headers. Currently I have it checking to see if a row has a new group header and adding a list item with a CSS class to differentiate it from the rest of the list items. What I'd like to do is make the non-header list items show up as normal hyperlinks. I know you can add DisplayMode="HyperLink" to the .aspx, but that applies to every element, including the header items. I'm looking for suggestions on the best way to add link styling to the items that should have them while leaving the group headers as normal text.
Here is the code so far:
The aspx:
<asp:BulletedList ID="reportsList" runat="server"></asp:BulletedList>
The function:
protected void BuildReportList(DataTable dt)
{
string groupHeader = "";
foreach (DataRow row in dt.Rows)
{
if (row["su2_description"].ToString().Trim() != groupHeader)
{
groupHeader = row["su2_description"].ToString().Trim();
ListItem myHeader = new ListItem();
myHeader.Text = row["su2_description"].ToString();
myHeader.Attributes.Add("Class", "groupHeader");
reportsList.Items.Add(myHeader);
}
ListItem myItem = new ListItem();
myItem.Text = row["prg_menu"].ToString();
myItem.Attributes.Add("title", row["prg_description"].ToString());
myItem.Attributes.Add("onClick", "runReport(this);");
myItem.Attributes.Add("value", row["prg_path"].ToString().Trim());
reportsList.Items.Add(myItem);
}
}
You can see from the code that the list items are using onClick, so they ARE links, but they don't have the standard styling to accompany a link. Rather than writing CSS for the group headers to negate all the HTML styling caused by DisplayMode="HyperLink" on the BulletedList, is there a way to add an attribute to the appropriate items to make them dynamically be recognized as links?
Upvotes: 0
Views: 406
Reputation: 63966
This is a long shot since I haven't tried it but I imagine this would work:
The items that are not headers, add a style attribute and set both, text-decoration
to underline and any color you'd like for the hyperlink appearance:
myItem.Attributes.Add("style", "text-decoration:underline; color:blue;");
Upvotes: 1