如何在gridview asp.net中为数字添加逗号

时间:2017-08-09 17:24:47

标签: c# asp.net gridview

我正在运行VS 2013.我正在尝试为数字添加逗号(前2000应为2,000)。我使用了DataFormatString="{0:N0}",但它没有用。

还有其他解决方案吗?

这是我的标记:

<asp:Label ID="gvCaptionN" CssClass="gvCaption" runat="server">NEW FIRST TIME FRESHMAN</asp:Label><br />
<asp:GridView Width="800px" ID="MyGridView1" DataSourceID="DataSource1" 
     AutoGenerateColumns="false" runat="Server"
     BorderColor="#555555" HorizontalAlign="Center"
     Font-Names="Verdana" Font-Size="12px" AllowSorting="True" EmptyDataRowStyle-Font-Bold="true" EmptyDataRowStyle-ForeColor="#CC0000">
     <EmptyDataTemplate>*** No data available ***</EmptyDataTemplate>
     <%-- Do not put the header styles in separate headerstyle tag, 
          because when exporting to excel, that will change the color of 
          first row even outside the table in Excel --%>
     <Columns>
         <asp:BoundField HeaderText="NEW FIRST-TIME FRESHMEN" 
              HtmlEncode="false" DataField="NEW FIRST-TIME FRESHMEN" 
              ItemStyle-HorizontalAlign="Left"
              HeaderStyle-BackColor="#CC0000" HeaderStyle-BorderColor="#555555" 
              ItemStyle-BorderColor="#555555" HeaderStyle-ForeColor="#FFFFFF" 
              HeaderStyle-Width="260px" ReadOnly="true" 
              DataFormatString="{0:N0}" />
         <asp:BoundField HeaderText="Last_Term" DataField="Last_Term" 
              ItemStyle-HorizontalAlign="Right" 
              HeaderStyle-BackColor="#CC0000" HeaderStyle-BorderColor="#555555" 
              ItemStyle-BorderColor="#555555" HeaderStyle-ForeColor="#FFFFFF" 
              HeaderStyle-Width="125px" ReadOnly="true" 
              DataFormatString="{0:N0}"  /> 
      </Columns>
</asp:GridView>                                             
<asp:SqlDataSource ID="DataSource1" runat="server" 
     onselecting="DataSource1_Selecting"  DataSourceMode="DataSet"  
     ConnectionString="<%$ ConnectionStrings:ConnStringExtracts_IRDW %>"
     EnableCaching="true" CacheDuration="10800"
     SelectCommand="dbo.SP_FB_UNCERT_ENR_IRDW" 
     SelectCommandType="StoredProcedure">
     <SelectParameters>
         <asp:Parameter Name="reportType" Type="String" DefaultValue="UNCERTNEWFRESH" />
         <asp:ControlParameter ControlID="ENRDropDownList" PropertyName="SelectedValue" Name="Term"
              Type="int32" DefaultValue="20172" />
     </SelectParameters>
 </asp:SqlDataSource>

0 个答案:

没有答案