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

[Solved] Need Oracle's, decode function functionality iin GridColumn

1 Answer 49 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Lee asked on 23 Mar 2010, 06:47 PM
Hi

We have a column SexCode which can be 0 or 1 , female and male respectively.
I want Grid column to display Male if value = 1 and Female if value = 0.

I can do this with lookup column but then i will need a datasouce, which i want to avoid.
I can also do this in SQL Query itself, but then i don;t want to increase size of query output, when it can be done at client side.

Can this be done ?

Regards
Leee.

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 24 Mar 2010, 03:21 PM
Hello Lee,

You can achieve this behavior if you subscribe for the CellFormatting event. Hence, you can customize the Text property of the cell with desired look up value. You can use the following code snippet:

private void radGridView_CellFormatting(object sender, CellFormattingEventArgs e)
{
    GridViewDataColumn dataColumn = e.CellElement.ColumnInfo as GridViewDataColumn;
 
    if (dataColumn != null && dataColumn.UniqueName == "SexCode")
    {
       int id = Convert.ToInt32(e.CellElement.RowInfo.Cells["SexCode"].Value);
 
       if (id == 1)
       {
           e.CellElement.Text = "Male";
       }
       else
       {
           e.CellElement.Text = "Female";
       }
 
       return;
    }
 
    e.CellElement.ResetValue(LightVisualElement.TextProperty, Telerik.WinControls.ValueResetFlags.Local);
}

If you have further questions feel free to write us back.

All the best,
Svett
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Lee
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or