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

Changing an item's text at runtime

2 Answers 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 18 Nov 2008, 11:30 AM
Hi,

I have a RadGrid which is bound to a datasource. In one column it might happen that
the item's name is an empty string. In this case I want to display "No name" instead of
nothing.
I tried to do this using the OnItemDataBound handler but I don't know how to access
the Item's text. How can I do this?

Best regards,
Robert

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Nov 2008, 11:47 AM
Hello robert,

You can try out the following code to display custom text in an empty cell:
cs:
  protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    {        
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            if (dataItem["ProductName"].Text == String.Empty) 
            { 
                dataItem["ProductName"].Text = "No name"
            }            
        } 
    } 

Thanks
Princy.
0
Daniel
Telerik team
answered on 18 Nov 2008, 12:23 PM
Hello Robert,

An easier approach would be the following:
<telerik:GridBoundColumn  
DataField="ID"  
DataType="System.Int32"  
EmptyDataText="No name" 
UniqueName="ID"
</telerik:GridBoundColumn> 

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Daniel
Telerik team
Share this question
or