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

Help: RadGrid convert integer value to string or bool

2 Answers 375 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gábor
Top achievements
Rank 1
Gábor asked on 07 Aug 2012, 11:11 AM
HI!

Here is my problem:

I have a List of objects. My objects contain multiple data fields, and I want to browse and edit them with a telerik RadGrid control. The grids datasource is the list of the objects. The objects have an integer data field, what I'd like to replace in the grid with something else.
So if the fields value is 0 then a "No" string should appear in the grid in place of the number. In other cases the "Yes" would be the text in the grid. Checked and unchecked checkboxes would be also perfect.
Sorry for my bad English,
Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 07 Aug 2012, 11:24 AM
Hi,

Try the following code to change the text based on datafield value.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
 {
    if (e.Item is GridDataItem)
     {
        GridDataItem item = (GridDataItem)e.Item;
         if (item["UniqueName"].Text == "1")
         {
            item["UniqueName"].Text = "yes";
         }
          if (item["UniqueName"].Text == "0")
         {
            item["UniqueName"].Text = "no";
         }
    }
}

Thanks,
Shinu.
0
Gábor
Top achievements
Rank 1
answered on 07 Aug 2012, 12:18 PM
Still doesn't work.
Here is the column:
<telerik:GridBoundColumn DataField="aktivalt" HeaderText="AktĂ­v" UniqueName="akt"/>
"aktivalt" is the integer field of the class.
I copypasted your code and changed the "UniqueName" to "akt" .
The error message I recieved: "Cannot find a cell bound to column name 'akt' ".

Update: It's working. The problem was caused by the rows of the detailtables. I just had to put your code in a try block to ignore the grid rows without "akt".

Thank You!
Tags
Grid
Asked by
Gábor
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Gábor
Top achievements
Rank 1
Share this question
or