RadDataForm Conditional Formatting

2 posts, 0 answers
  1. Matt
    Matt avatar
    13 posts
    Member since:
    Aug 2015

    Posted 27 Oct 2015 Link to this post

    Is there a code-behind example of how to apply conditional formatting inside of an ItemTemplate within a RadDataForm?

    i.e. if the value of a label is "this", then I will format it to be red.

  2. Konstantin Dikov
    Konstantin Dikov avatar
    1744 posts

    Posted 28 Oct 2015 Link to this post

    Hi Matt,

    For achieving the desired result you could handle the server-side OnItemDataBound event of the RadDataForm, get reference to the Label control and depending on the value of the label, customize its appearance:
        <asp:Label runat="server" ID="Label1" Text='<%#Eval("SomeDataField")%>'></asp:Label>

    And the code-behind:
    protected void RadDataForm2_ItemDataBound(object sender, RadDataFormItemEventArgs e)
        if (e.Item is RadDataFormItem)
            RadDataFormItem item = e.Item as RadDataFormItem;
            Label label = item.FindControl("Label1") as Label;
            if (label != null && label.Text == "this")
                label.ForeColor = System.Drawing.Color.Red;

    Hope this helps.

    Konstantin Dikov
  3. DevCraft R3 2016 release webinar banner
Back to Top