简体   繁体   中英

How to remove commas from numbers string in DataGrid

I have a DataGrid that is displaying Customer's phone numbers but the DataGrid is adding in commas to the numbers:

在此处输入图片说明

Its ok if the phone number has spaces in it like the second row but if they enter the number without spaces, then the DataGrid automatically formats the numbers.

Code for DataGrid:

   <asp:DataGrid CssClass="tblResults" runat="server" OnItemCreated="dgCRMContacts_ItemCreated" OnItemDataBound="dgCRMContacts_ItemDataBound" ID="dgCRMContacts" DataKeyField="ID" AutoGenerateColumns="false">
   <HeaderStyle CssClass="tblResultsHeader" />
   <AlternatingItemStyle BackColor="#EEEEEE" />                        
        <Columns>
              <asp:BoundColumn DataField="ContactName" HeaderText="Contact Name"></asp:BoundColumn>
              <asp:BoundColumn DataField="ContactPhone" HeaderText="Phone Number"></asp:BoundColumn>                                            
        </Columns>
</asp:DataGrid>

ContactPhone in the database doesn't contain any commas. It is a type string . The commas only get added when the number is displayed on the DataGrid. How do I stop the phone number from automatically formatting?

if you want to use method in filds or change data on it you should use templatecolumn such as :

<asp:TemplateColumn HeaderText="Principal Office">
   <ItemTemplate>
      <%# replasecoma_method(Eval("pos")) %>
   <ItemTemplate>
<asp:TemplateColumn>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM