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
| RadGrid oGrid = new RadGrid(); |
| oGrid.ID = "ProjectGrid"; |
| oGrid.Skin = "WebBlue"; |
| //oGrid.Width = new Unit(100, UnitType.Percentage); |
| oGrid.AutoGenerateColumns = false; |
| oGrid.AllowPaging = true; |
| oGrid.AllowSorting = true; |
| oGrid.ClientSettings.Resizing.AllowColumnResize = true; |
| oGrid.ClientSettings.AllowColumnsReorder = true; |
| //oGrid.MasterTableView.allow |
| oGrid.NeedDataSource += new GridNeedDataSourceEventHandler(oGrid_NeedDataSource); |
| oGrid.MasterTableView.Columns.Clear(); |
| GridButtonColumn Print = new GridButtonColumn(); |
| Print.ButtonType = GridButtonColumnType.ImageButton; |
| Print.ImageUrl = @"\_layouts\wpresources\images\print.gif"; |
| Print.UniqueName = "Print"; |
| Print.CommandName = "Print"; |
| Print.ItemStyle.Width = new Unit(10, UnitType.Pixel); |
| oGrid.MasterTableView.Columns.Add(Print); |
| oGrid.ItemCommand += new GridCommandEventHandler(oGrid_ItemCommand); |
| oGrid.ItemCreated += new GridItemEventHandler(oGrid_ItemCreated); |
| void oGrid_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridDataItem) |
| { |
| GridDataItem dataItem = e.Item as GridDataItem; |
| ImageButton imgbtn1 = dataItem["Print"].Controls[0] as ImageButton; |
| ImageButton imgbtn2 = dataItem["CreateNew"].Controls[0] as ImageButton; |
| ImageButton imgbtn3 = dataItem["MakeActive"].Controls[0] as ImageButton; |
| ImageButton imgbtn4 = dataItem["CopyToClipboard"].Controls[0] as ImageButton; |
| imgbtn1.OnClientClick = String.Format(@"{0}.__doPostBack(""{1}"",""{2}"");return false;", ((RadAjaxManager)FindControl("RadAjaxManager1")), imgbtn1.UniqueID, imgbtn1.CommandArgument); |
| } |
| } |
| Partial Class usercontrols_mainNav |
| Inherits System.Web.UI.UserControl |
| Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
| If System.IO.Path.GetDirectoryName(HttpContext.Current.Request.FilePath).ToLower = "score_selector/Default.aspx" Then |
| RadTabStrip1.SelectedIndex = 1 |
| Else |
| RadTabStrip1.SelectedIndex = 0 |
| End If |
| End Sub |
| End Class |
| <root> |
| <tools> |
| <tool type="custom" name="NewCustomButton" Text="Add Premium Image"/> |
| </tools> |
| </root> |
| <style> |
| .retoolbar.Web20 .NewCustomButton |
| { |
| background-image: url(../../images/icons/flag-g.gif); |
| } |
| </style> |
| <telerik:radeditor ID="RadEditor1" runat="server" |
| ToolsFile="~/XMLConfigFiles/ToolsFileDemo.xml" EditModes="All" Height="400px" |
| Skin="Web20" ToolbarMode="ShowOnFocus" Width="670px"> |
| </telerik:radeditor> |
| <telerik:GridButtonColumn HeaderText="Download" Text="Get Report" |
| UniqueName="dldReportColumn" CommandName="PullReport"> |
| </telerik:GridButtonColumn> |
| Protected Sub BatchGrid_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles BatchGrid.ItemCommand |
| If e.CommandName = "PullReport" Then |
| Dim chosen As GridDataItem = DirectCast(e.Item, GridDataItem) |
| Dim folder As String = chosen("folder").Text |
| Dim file As String = chosen("file").Text |
| 'The first task is to ensure that the file exists. |
| Dim fullPath As String = Path.Combine(folder, file) |
| Dim fi As FileInfo = New FileInfo(fullPath) |
| If fi.Exists() Then |
| Dim id As String = chosen("BatchID").Text |
| Response.ClearContent() |
| Response.AddHeader("Content-disposition", "attachment; filename=" & file) |
| Response.AddHeader("Content-Length", fi.Length) |
| Response.ContentType = "application/octet-stream" |
| Response.TransmitFile(fullPath) |
| Response.Flush() |
| Response.End() |
| End If |
| End If |
| End Sub |

| protected void RadSkinManager1_PreRender(object sender, EventArgs e) |
| { |
| DataTable table = new DataTable(); |
| DataRow row; |
| table.Columns.Add("ImgUrl"); |
| table.Columns.Add("val"); |
| table.Columns.Add("txt"); |
| row = table.NewRow(); |
| row.ItemArray = new string[] { "images/default.gif", "Default", "Default" }; |
| table.Rows.Add(row); |
| row = table.NewRow(); |
| row.ItemArray = new string[] { "images/black.gif", "Black", "Black" }; |
| table.Rows.Add(row); |
| row = table.NewRow(); |
| row.ItemArray = new string[] { "images/forest.gif", "Forest", "Forest" }; |
| table.Rows.Add(row); |
| RadComboBox skinChooser = RadSkinManager1.FindControl("SkinChooser") as RadComboBox; |
| skinChooser.DataSource = table; |
| skinChooser.ItemTemplate = new IMGTemplate("ImgUrl"); |
| skinChooser.DataTextField = "txt"; |
| skinChooser.DataValueField = "val"; |
| skinChooser.Width = 240; |
| skinChooser.Height = 202; |
| skinChooser.DataBind(); |
| skinChooser.SelectedValue = RadSkinManager1.Skin; |
| } |
| class IMGTemplate : ITemplate |
| { |
| string pathColumn; |
| public IMGTemplate(string imgPathColumn) |
| { |
| pathColumn = imgPathColumn; |
| } |
| public void InstantiateIn(Control c) |
| { |
| Image imgt = new Image(); |
| imgt.DataBinding += new EventHandler(imgDataBinding); |
| c.Controls.Add(imgt); |
| } |
| void imgDataBinding(object sender, EventArgs e) |
| { |
| Image img_ = (Image)sender; |
| RadComboBoxItem item = (RadComboBoxItem)img_.BindingContainer; |
| DataRowView drv = ((DataRowView)item.DataItem); |
| img_.ImageUrl = drv[pathColumn].ToString(); |
| } |
| } |