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

GridBoundColumn - do not show zero for number columns?

2 Answers 424 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paweł
Top achievements
Rank 1
Paweł asked on 13 Oct 2008, 09:04 AM
Let's have the following pseudo-code:

<telerik:RadGrid>
        <Columns>
            <telerik:GridBoundColumn DataField="SomeInt32Column" />
        </Columns>
</telerik:RadGrid>

The default behaviour is:
if null - show empty string
else - show number

What i would like to get is:
if null or zero - show empty string
else - show number

I was trying to accomplish it with DataFormatString, but without success so far. Is there a silmple way to do this?

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 13 Oct 2008, 11:55 AM
Hi Pawet,

Try the following code snippet to achieve the desired scenario.

ASPX:
 <telerik:GridBoundColumn DataField="RollNo"  HeaderText="RollNo"     UniqueName="RollNo"
                    </telerik:GridBoundColumn> 

CS:
  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataitem = (GridDataItem)e.Item; 
            string strVal = dataitem["RollNo"].Text.ToString(); 
            if((strVal=="0")||(strVal==null)) 
            { 
                dataitem["RollNo"].Text ="&nbsp"
            } 
        } 
 
    } 


Thanks
Shinu.
0
Paweł
Top achievements
Rank 1
answered on 14 Oct 2008, 02:06 PM
Thanks, Shinu.
That will certainly help, although I hoped that there is a cleaner way to do it. Thanks anyway!
Tags
Grid
Asked by
Paweł
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Paweł
Top achievements
Rank 1
Share this question
or