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

Cells' values

1 Answer 69 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 25 Mar 2009, 08:32 AM
Hi everybody.
I have a question. In the code below I'm trying replace cells with a specific value with an empty string, but this step changes also the values in the database table for corresponding cells.
 
GridViewRowCollection rowCollection = someGridView.Rows;
foreach (GridViewRowInfo info in rowCollection)
{
    if (info.Cells["someColumn"].Value.ToString() == "someValue")
    {
         info.Cells["someColumn"].Value = "";
    }
}


How can I avoid such a behavior, without  creating another foreach loop in order to restore previous values?
Thanks in advance.
Frank.

1 Answer, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 25 Mar 2009, 01:40 PM
Hello Frank Effenberger,

You should process the CellFormatting event if you want to change only the text displayed on the screen. You should change the Text property of the desired cells. Here is a sample:

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) 
    GridDataCellElement cell = e.CellElement as GridDataCellElement; 
    if (cell != null && cell.ColumnIndex == 2 && (int)cell.Value > 5) 
    { 
        cell.Text = ""
    } 

I hope this helps. If you need further assistance, I will be glad to help.

Kind regards,
Jack
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Frank
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or