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

Remove comma from value of a numeric filter for radgrid

7 Answers 796 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fraz
Top achievements
Rank 1
Fraz asked on 04 May 2010, 05:59 PM
This might be an easy question but i can not find the answer.  If you have a radgrid with a filter on a numeric value it shows that value in the filter box with a comma if it is over 999 (NOT in the data itself).  I.E.  you want to filter on OrderID and that is numeric.  If you try to filter on OrderID and the value you are looking for is 12345 in the filter box it shows it as 12,345.  is there a way that the filter box will not show comma's? 

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 May 2010, 06:31 AM
Hi,

You could access the RadNumericTextBox in the ItemCreated event of the grid and remove the comma separator by setting the GroupSeparator property as shown in the following code..

ASPX:

<
telerik:GridNumericColumn DataField="OrderID" HeaderText="GridNumericColumn" UniqueName="NumericColumn" 
                        SortExpression="OrderID" > 


CS:

        protected
 void RadGrid2_ItemCreated(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridFilteringItem) 
            { 
                GridFilteringItem filerItem = (GridFilteringItem)e.Item; 
                RadNumericTextBox textItem = (RadNumericTextBox)filerItem["NumericColumn"].Controls[0]; 
                textItem.NumberFormat.GroupSeparator = ""
            } 
        } 

Hope this would help you.

Regards,
Princy.
0
Fraz
Top achievements
Rank 1
answered on 05 May 2010, 04:14 PM

Thanks for the response Princy

I have tried to do this in both markup and code behind and i can not get either to work.  Below is my code, could someone let me know what i am doing wrong?

ASPX

<td class="ms-formlabel" colspan="2">  
    <meis:MeisRadGrid ID="rgCenters" MeisAddButtonAccessLevel="Compose" runat="server" 
        AllowPaging="True" AutoGenerateColumns="false" AllowSorting="True" CommandItemDisplay="Top" 
        GridLines="None" PageSize="20" AllowFilteringByColumn="true" OnItemCommand="rgCenters_ItemCommand" 
        GroupingSettings-CaseSensitive="false" OnNeedDataSource="rgCenters_NeedDataSource">  
        <MasterTableView DataKeyNames="centerid">  
            <Columns> 
                <telerik:GridNumericColumn DataField="centerid" ColumnEditorID="centeridEditor" HeaderText="<%$Resources:meis,Labels_ID%>" 
                    SortExpression="centerid" UniqueName="NumericColumn" /> 
                <telerik:GridHyperLinkColumn DataNavigateUrlFields="centerid" HeaderText="<%$Resources:meis,Labels_Name%>" 
                    DataNavigateUrlFormatString="CenterEdit.aspx?CenterID={0}" DataType="System.String" 
                    DataTextField="Name" DataTextFormatString="{0}" SortExpression="Name" /> 
                <telerik:GridBoundColumn DataField="shortname" HeaderText="<%$Resources:meis,Labels_State%>" 
                    SortExpression="shortname" /> 
                <telerik:GridBoundColumn DataField="CenterStatusName" HeaderText="<%$Resources:meis,Labels_AccountStatus%>" 
                    SortExpression="CenterStatusName" /> 
            </Columns> 
            <RowIndicatorColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
        </MasterTableView> 
    </meis:MeisRadGrid> 
    <telerik:GridNumericColumnEditor ID="centeridEditor" runat="server">  
        <NumericTextBox runat="server">  
            <NumberFormat GroupSeparator="" /> 
        </NumericTextBox> 
    </telerik:GridNumericColumnEditor> 
</td> 
 and c# code behind
protected void rgCenters_ItemCreated(object sender, GridItemEventArgs e)    
        {    
            if (e.Item is GridFilteringItem)    
            {    
                GridFilteringItem filerItem = (GridFilteringItem)e.Item;    
                RadNumericTextBox textItem = (RadNumericTextBox)filerItem["NumericColumn"].Controls[0];    
                textItem.NumberFormat.GroupSeparator = "";    
            }    
        }  

After i posted i relized that i forgot to set the OnItemCreated property of the grid in the markup(ASPX).  Once i did that the code behind works.  So thanks Princy.
 

 and c# code behind

I would like to know why the code in the parkup does not work I.E.

<telerik:GridNumericColumnEditor ID="centeridEditor" runat="server">  
        <NumericTextBox runat="server">  
            <NumberFormat GroupSeparator="" /> 
        </NumericTextBox> 
    </telerik:GridNumericColumnEditor>

0
james brown
Top achievements
Rank 1
answered on 05 May 2010, 08:32 PM
I have a grid that is setting AutoGenerateColumns to true.  Is it possible to do this for all numeric columns in a grid?

Thanks in advance.
0
Princy
Top achievements
Rank 2
answered on 06 May 2010, 07:05 AM
Hi,

When you use automatically-generated columns, a column is added for every field of the data source to which the table view is bound. These columns can be accessed using the AutoGeneratedColumns property collection. In order to remove the comma separator from the numeric filter boxes you could loop through the GridNumericColumns in the column collection and set GroupSeparator property to "".Check out the following code.

CS:
      
        protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) 
        { 
           if (e.Item is GridFilteringItem) 
            { 
                foreach (GridColumn nColumn in RadGrid1.MasterTableView.AutoGeneratedColumns) 
                { 
                    if (nColumn is GridNumericColumn)
                    { 
                        GridFilteringItem filerItem = (GridFilteringItem)e.Item; 
                        RadNumericTextBox textItem = (RadNumericTextBox)filerItem[nColumn.UniqueName].Controls[0]; 
                        textItem.NumberFormat.GroupSeparator = ""
                    } 
                }                        
            } 
        } 

I hope this helps.

Regards,
Princy.
0
james brown
Top achievements
Rank 1
answered on 06 May 2010, 02:11 PM
Works like a charm.  Thanks!
0
Laurie
Top achievements
Rank 2
answered on 19 Aug 2010, 11:02 PM
This thread is very helpful.  Thanks!
0
Naresh
Top achievements
Rank 1
answered on 09 Mar 2012, 08:04 AM
Hi,

my requirement is to separate the numeric values with commas in telerik grid column can u please help me out to do this ...
Tags
Grid
Asked by
Fraz
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Fraz
Top achievements
Rank 1
james brown
Top achievements
Rank 1
Laurie
Top achievements
Rank 2
Naresh
Top achievements
Rank 1
Share this question
or