【问题标题】:How to remove commas from numbers string in DataGrid如何从 DataGrid 中的数字字符串中删除逗号
【发布时间】:2016-07-11 09:57:13
【问题描述】:

我有一个显示客户电话号码的 DataGrid,但 DataGrid 在数字中添加逗号:

如果电话号码中像第二行一样有空格,则可以,但如果他们输入的号码不带空格,则 DataGrid 会自动格式化号码。

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 不包含任何逗号。它是一个类型string。只有在 DataGrid 上显示数字时才会添加逗号。如何阻止电话号码自动格式化?

【问题讨论】:

    标签: c# asp.net datagrid formatting string-formatting


    【解决方案1】:

    如果您想在字段中使用方法或更改其上的数据,您应该使用模板列,例如:

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

    【讨论】:

      猜你喜欢
      • 2012-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 2019-01-10
      相关资源
      最近更新 更多