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

Changing Data while binding

1 Answer 153 Views
GridView
This is a migrated thread and some comments may be shown as answers.
fgalarraga
Top achievements
Rank 1
fgalarraga asked on 08 Jul 2007, 06:31 AM
Is there a way to change the data in a cell during the bind event?

Example: Date column, if the column = "01/01/1900" then column data = ""

How would you do this with the GridView Control?

Thank you,
Frank

1 Answer, 1 is accepted

Sort by
0
Phi
Top achievements
Rank 1
answered on 08 Jul 2007, 11:21 PM
Hi fgalarraga,

The way I would do this is to subscribe to the CellFormatting event of the GridView. Within the handler, you can check if the cell value is a date, check if it is 01/01/1900, and reformat accordingly:

this.radGridView1.CellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(this.radGridView1_CellFormatting);  
 
private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)  
{  
    if (e.CellElement.Value is DateTime)  
    {  
        DateTime cellDateValue = (DateTime) e.CellElement.Value;  
        if (cellDateValue == new DateTime(1900, 1, 1))  
            e.CellElement.Text = "";  
    }  

Cheers
Phi
Tags
GridView
Asked by
fgalarraga
Top achievements
Rank 1
Answers by
Phi
Top achievements
Rank 1
Share this question
or