This is a migrated thread and some comments may be shown as answers.

Show Path (breadcrumb) CSS Styling e.g. Last Item

0 Answers 136 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Ian Turvey
Top achievements
Rank 1
Ian Turvey asked on 07 Jul 2009, 04:15 PM

I have used Telerik's example http://demos.telerik.com/aspnet-ajax/menu/examples/programming/showpath/defaultcs.aspx method to include a hyperlinked showpath / breadcrumb and wish to apply css styling to eg the last item
these are in the last row of a repeater
root > sub1 > sub2 >
sub3

Protected void BreadCrumbRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)  

{ 

if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem)

                {

     this.ItemCount.Text = Convert.ToString(this.BreadCrumbRepeater.Items.Count); //show item count in a label on asp page

 HyperLink BreadCrumbHyperLink = ((HyperLink)(e.Item.FindControl("BreadCrumbHyperLink")));

 if (e.Item.ItemIndex == BreadCrumbRepeater.Items.Count) // I found the item count returns the correct index so need for -1

        {
                 

BreadCrumbHyperLink.CssClass = "last";

         }

    else

        {

             BreadCrumbHyperLink.CssClass = "middle";

         }

    }
}

Which dosn't work, if I manually set if (e.Item.ItemIndex == 1) then this will show 0 and 2 as css middle and 1 as css last.

I then thought ok I'll never have more than 5-10 levels deep so I can just manually set it in a nested if statement.

Something along the lines of

 

                            if (BreadCrumbRepeater.Items.Count == 2)

                            {

                                

 

                                if (e.Item.ItemIndex == 2)

                                {

                                    BreadCrumbHyperLink.CssClass = "last";

                                }

                                else

                                {

                                    BreadCrumbHyperLink.CssClass = "middle";

                                }
                             }
 
                            else if (BreadCrumbRepeater.Items.Count == 1)

                            {

                                

 

                                if (e.Item.ItemIndex == 1)

                                {

                                    BreadCrumbHyperLink.CssClass = "last";

                                }

                                else

                                {

                                    BreadCrumbHyperLink.CssClass = "middle";

                                }
                             } 

                            else if (BreadCrumbRepeater.Items.Count == 0)

                            {

                                

 

                                if (e.Item.ItemIndex == 0)

                                {

                                    BreadCrumbHyperLink.CssClass = "last";

                                }

                             } 

Which again didn't work

I then look ed at using a switch case statment

                        switch (Convert.ToString(BreadCrumbRepeater.Items.Count))

                {

                    case "2":

 

                        gredy.Text = "two";

 

                        if (e.Item.ItemIndex == 0)

                        {

                            BreadCrumbHyperLink.CssClass = "middle";

                        }

                        else if (e.Item.ItemIndex == 1)

                        {

                            BreadCrumbHyperLink.CssClass = "middle";

                        }

                        else if (e.Item.ItemIndex == 2)

                        {

                            BreadCrumbHyperLink.CssClass = "last";

                        }

                        break;

 

                    case "1":

 

                       

 

                        if (e.Item.ItemIndex == 1)

                        {

                            BreadCrumbHyperLink.CssClass = "last";

                        }

                        else if (e.Item.ItemIndex == 0)

                        {

                            BreadCrumbHyperLink.CssClass = "middle";

                        }

                        break;

 

                    case "0":

 

                       

 

                        if (e.Item.ItemIndex == 0)

                        {

                            BreadCrumbHyperLink.CssClass = "last";

                        }

                        break;

Which again doesn’t work I know the logic for the switch if statements works because I can use it to set labels values for a test.

So the problem seems to be just applying the style to the correct hyperlink item.

Any suggestions would be helpful

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

No answers yet. Maybe you can help?

Tags
Menu
Asked by
Ian Turvey
Top achievements
Rank 1
Share this question
or