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

    hi

    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
    Admin
    Danail Vasilev avatar
    1494 posts

    Posted 26 Feb 2015 Link to this post

    Hello,

    You can use the conditional operator like this:

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

    C#:
    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();
    }



    Regards,
    Danail Vasilev
    Telerik
     

    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. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top