Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Grid > How to Customize the Binding of a Column?
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered How to Customize the Binding of a Column?

Feed from this thread
  • Pooya Intermediate avatar

    Posted on Jun 27, 2011 (permalink)

    1) I have a datafield which is bound to my RadGrid called YesNo which returns values of 0 and 1.

    Currently I have added a boundcolumn and it displays 0 and 1 obviously.

    How could I show Yes when 1 appears and No when 0?

    2) I have 2 other data fields, Count1 and Count2 which return float values.

    I'd need to display one column which is bound to the Count1/Count2.

    For example, if Count1 is 20 and Count2 is 100, it should display 0.20.

    How could I achieve this?

    Many thanks,

  • Pooya Intermediate avatar

    Posted on Jun 27, 2011 (permalink)

    I fixed my second problem by adding a CalculatedColumn like this:

    protected void AddCalculatedColumn(string headerText, string expression, string dataFormatString, params string[] dataFields)
    {
        var boundColumn = new GridCalculatedColumn
                              {
                                  DataFields = dataFields,
                                  HeaderText = headerText,
                                  Expression = expression,
                                  DataFormatString = dataFormatString,
                                  ItemStyle = { CssClass = RadGridCssClasses.ItemBoundColumn },
                                  HeaderStyle = { CssClass = RadGridCssClasses.HeaderBoundColumn }
        };
     
        Product.Columns.Add(boundColumn);
    }

    and use it like:

    expression: {0}/{1}
    DataFormatString: {0:0.00}%

    Still haven't figured out my first question?

  • Posted on Jun 28, 2011 (permalink)

    Hello Pooya,

    You can try the following server side code to achieve the first requirement

    cs:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               GridDataItem item = (GridDataItem)e.Item;
               string txt= item["YesNo"].Text.ToString();
               if  (txt== "1")
               {
                   item["YesNo"].Text = "yes";
                }
           }
       }

    Thanks,
    Princy

  • Pooya Intermediate avatar

    Posted on Jun 28, 2011 (permalink)

    Thanks but using ItemDataBound() makes my code design a bit ugly!

    Is there any way to do this using something like CalculatedColumn?

    Where could I find some samples on how to use Expression?
     
    Regards,

  • Pooya Intermediate avatar

    Posted on Jun 28, 2011 (permalink)

    Great, found the right expression!

    iif({0}.Value=1,\"Yes\",\"No\")"

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Grid > How to Customize the Binding of a Column?