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

Set text color in xml data source

3 Answers 56 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Sean Severson
Top achievements
Rank 1
Sean Severson asked on 18 Jul 2013, 04:25 PM
I am creating xml dynamically as the data source for a panelbar control.  Is there a way to set the color of the text in the panel bar items via the xml?

Thanks!

Sean Severson

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 23 Jul 2013, 09:18 AM
Hello,

An easy and convenient way of achieving such functionality would be to set the item text color as attribute in your XML file and use the RadPanelBar ItemDataBound server-side event handler as shown in the code snippet below:
//code behind
protected void RadPanelBar1_ItemDataBound(object sender, RadPanelBarEventArgs e)
    {
        XmlElement element = (XmlElement)e.Item.DataItem;
        //assume that the item's text is set as textColor attribute in your xml file
        string textColor = element.Attributes["textColor"].ToString();
        e.Item.Style.Add("color", textColor);
    }


Regards,
Boyan Dimitrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Sean Severson
Top achievements
Rank 1
answered on 23 Jul 2013, 12:36 PM

Boyan,

Thank you for your suggestion.  I opted for a different solution, though.  I created css styles for the various colors I needed and then added the CssClass attribute into the Item when it was dynamically created.  Here is the function from my PanelBarFactory class used to create a single Item.  There are some helper methods used by this function that I did not include, but I think you get the idea.

Private Function GetStatusReportPanelXML(ByVal sr As StatusReport, ByVal level As Integer) As String
       Dim statusReportText As String = sr.Created.ToString()
       Dim trimmedStatusReportText As String = GetTrimmedPanelText(statusReportText, level)
       Dim toolTipText As String = String.Empty
       If statusReportText <> trimmedStatusReportText Then
           toolTipText = System.Web.HttpUtility.HtmlEncode(statusReportText)
       End If
       statusReportText = trimmedStatusReportText
       'Add the tool tip text for the Status Report Type and created by
       Dim srToolTipText As StringBuilder = New StringBuilder
       Dim textColor As String = String.Empty
       If toolTipText <> String.Empty Then
           srToolTipText.AppendFormat("{0} ", toolTipText)
       End If
       srToolTipText.AppendFormat("{0} ", String.Format("Memo Type: {0}", sr.MemoTypeDescription))
       srToolTipText.AppendFormat("{0}", String.Format("Created By: {0}", sr.CreatedByName))
       If Not sr.IsDeleted Then
           If CBool(sr.MemoType = CInt(1).ToString) Or CBool(sr.MemoType = CInt(5).ToString) Then
               If sr.isYearEndPopulated = True Then
                   textColor = "srGreen"
               Else
                   textColor = ""
               End If
           ElseIf CBool(sr.MemoType = CInt(3).ToString) Or CBool(sr.MemoType = CInt(4).ToString) Then
               textColor = "srRed"
           ElseIf CBool(sr.GetMemoTypeEnum(CStr(2))) Then
               textColor = "srBlue"
           End If
       End If
       Return String.Format(" <Item Text='{0}' ToolTip='{1}' Value='{2}' CssClass='{3}' />", statusReportText, srToolTipText.ToString(), VirtualPathUtility.ToAbsolute(String.Format("~/Claim/WC/StatusReports/WCStatusReports.aspx?Claim={0}&StatusReportID={1}", _claim.ClaimNumber, sr.ID)), textColor.ToString)
   End Function

.srRed
{
    color:Red !important;
}
  
.srGreen
{
    color:Green !important;
}
  
.srBlue
{
    color:Blue !important;
}

Sean Severson
0
Boyan Dimitrov
Telerik team
answered on 26 Jul 2013, 08:05 AM
Hello,

Thank you for sharing your solution with the community. I hope that someone will find it helpful and use it to implement similar functionality.

Regards,
Boyan Dimitrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
PanelBar
Asked by
Sean Severson
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Sean Severson
Top achievements
Rank 1
Share this question
or