Remove comma from value of a numeric filter for radgrid

8 posts, 0 answers
  1. Fraz
    Fraz avatar
    3 posts
    Member since:
    Apr 2010

    Posted 04 May 2010 Link to this post

    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? 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 May 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Fraz
    Fraz avatar
    3 posts
    Member since:
    Apr 2010

    Posted 05 May 2010 Link to this post

    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>

  5. james brown
    james brown avatar
    2 posts
    Member since:
    Nov 2009

    Posted 05 May 2010 Link to this post

    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.
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 May 2010 Link to this post

    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.
  7. james brown
    james brown avatar
    2 posts
    Member since:
    Nov 2009

    Posted 06 May 2010 Link to this post

    Works like a charm.  Thanks!
  8. Laurie
    Laurie avatar
    141 posts
    Member since:
    Feb 2007

    Posted 19 Aug 2010 Link to this post

    This thread is very helpful.  Thanks!
  9. Naresh
    Naresh avatar
    1 posts
    Member since:
    Mar 2012

    Posted 09 Mar 2012 Link to this post

    Hi,

    my requirement is to separate the numeric values with commas in telerik grid column can u please help me out to do this ...
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017