multiple if conditions on Text property

2 posts, 0 answers
  1. L
    L avatar
    295 posts
    Member since:
    Apr 2008

    Posted 25 Feb 2015 Link to this post


    How do i do a multiple if condition on a button text property?

    This is my sample code and i could not get it to work.

    Text='<%# If(Eval("status") = "Yes", "OK", else If(Eval("status") = "Pending", "Pending", "No"))%>'

    Thanks a lot
  2. Danail Vasilev
    Danail Vasilev avatar
    1476 posts

    Posted 26 Feb 2015 Link to this post


    You can use the conditional operator like this:

    <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource">
        <MasterTableView AutoGenerateColumns="false">
                <telerik:GridBoundColumn DataField="SellQuantity"></telerik:GridBoundColumn>
                        <telerik:RadButton ID="RadButton1" runat="server" Text='<%# ((int)Eval("ID") == 2) ? "OK": "Cancel" %>' />

    protected DataTable GetData()
        DataTable dt = new DataTable();
        dt.Columns.Add("ID", typeof(int));
        dt.Columns.Add("SellQuantity", typeof(int));
        dt.Columns.Add("SellDate", typeof(DateTime));
        dt.Rows.Add(1, 2, new DateTime(2011, 06, 12));
        dt.Rows.Add(2, 5, new DateTime(2011, 12, 12));
        dt.Rows.Add(3, 6, new DateTime(2012, 06, 17));
        dt.Rows.Add(4, 4, new DateTime(2012, 09, 18));
        dt.Rows.Add(5, 7, new DateTime(2013, 03, 18));
        return dt;
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        RadGrid1.DataSource = GetData();

    Danail Vasilev

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. DevCraft R3 2016 release webinar banner
Back to Top