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

how can i check and change the Text Of the DataBound column of My telerik RadGrid?

2 Answers 566 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Majid Darab
Top achievements
Rank 1
Majid Darab asked on 16 Sep 2010, 06:13 PM

hi my dear friends:

in my rad grid i have a boundColumn(system.string) that i want to change it's null value to another customize text...

how can i check and change the Text Of that DataBound column of My telerik RadGrid?

(what event should i use and how change the text?

is it possible to do that without codebehind and using BindingExpression(Conditional Expression))?)

thanks for your future answer

2 Answers, 1 is accepted

Sort by
0
Jamey Johnston
Top achievements
Rank 1
answered on 16 Sep 2010, 08:53 PM
In the codebehind, you can modify the output in the ItemDataBound event like below, just change "Nothing" to whatever message you want to display based on your condition.

 

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

 

{

 

    if (e.Item is GridDataItem)

 

    {

 

        GridDataItem dataItem = (GridDataItem)e.Item;

 

 

        if (string.IsNullOrEmpty(dataItem["Column1"].Text))
        {
            dataItem[
"Column1"].Text = "Nothing";
        }

 

    }
}

I believe you can also do the same in the aspx page I believe it would look something like this (going from memory), just replace "DataElement" with the field name from your data source:

Text='<%# string.IsNullOrEmpty(Eval("DataElement").ToString()) ? "Nothing" : Eval("DataElement") %>'

0
Majid Darab
Top achievements
Rank 1
answered on 17 Sep 2010, 12:38 AM
Really Really Thanks For ur Answer...

the below code is working perfectly :

protected void grd_ItemDataBound(object sender, GridItemEventArgs e)
{
 
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = (GridDataItem)e.Item;
 
        //if (string.IsNullOrEmpty(dataItem["Test"].Text))
        if(dataItem["Test"].Text == "&nbsp;")
        {
            dataItem["Test"].Text = "Empty";
            dataItem["Test"].ForeColor = ColorTranslator.FromHtml("#006E6E");
        }
    }
 
}

but i have some questions for the way #2
the grid databound column aspx code is like this :
<telerik:GridBoundColumn DataField="Test" FilterImageToolTip="فیلتر" HeaderText="column1"
    SortExpression="Test" UniqueName="Test">
    <HeaderStyle HorizontalAlign="Center" />
</telerik:GridBoundColumn>

as u see there is no text property here...
if u mean we should use a template column and a lable inside it , so in this way we lost filtering this column.
how can we fix the upper issue?

thanks in future advance
Tags
Grid
Asked by
Majid Darab
Top achievements
Rank 1
Answers by
Jamey Johnston
Top achievements
Rank 1
Majid Darab
Top achievements
Rank 1
Share this question
or