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

RadDataForm Conditional Formatting

1 Answer 33 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 27 Oct 2015, 03:34 PM

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.

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 28 Oct 2015, 11:35 AM
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:
<ItemTemplate>
    <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.


Regards,
Konstantin Dikov
Telerik
Tags
DataForm
Asked by
Matt
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or