In this article we will introduce with Display number thousand separate in FormView in ASP.NET
Display number thousand separate in FormView in ASP.NET
In this example you can see how We can use thousand separator for number. In this example we use a FormView Control and bind data with SqlDataSource and use thousand separate function in Price datafield.
NumberFormatFormView.aspx (Design Page):
NumberFormatFormView.aspx (source code):
<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master" AutoEventWireup="true" CodeFile="NumberFormatFormView.aspx.cs" Inherits="NumberFormatFormView" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div> <h2 style="color: Green"> Display number thousand seperate <br /> in FormView In ASP.NET 4, C#</h2> <asp:FormView ID="FormView1" runat="server" AllowPaging="True" CellPadding="4" DataKeyNames="ProductID" DataSourceID="SqlDataSource1" ForeColor="#333333" Width="269px" Font-Bold="True" Font-Names="Verdana" Font-Size="Small" Height="155px"> <EditItemTemplate> ProductID: <asp:Label ID="ProductIDLabel1" runat="server" Text='<%# Eval("ProductID") %>' /> <br /> ProductName: <asp:TextBox ID="ProductNameTextBox" runat="server" Text='<%# Bind("ProductName") %>' /> <br /> Price: <asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>' /> <br /> <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" /> <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /> </EditItemTemplate> <EditRowStyle BackColor="#999999" /> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <HeaderTemplate> Product Information </HeaderTemplate> <InsertItemTemplate> ProductID: <asp:TextBox ID="ProductIDTextBox" runat="server" Text='<%# Bind("ProductID") %>' /> <br /> ProductName: <asp:TextBox ID="ProductNameTextBox" runat="server" Text='<%# Bind("ProductName") %>' /> <br /> Price: <asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>' /> <br /> <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" /> <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /> </InsertItemTemplate> <ItemTemplate> ProductID: <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' /> <br /> ProductName: <asp:Label ID="ProductNameLabel" runat="server" Text='<%# Bind("ProductName") %>' /> <br /> Price: <asp:Label ID="PriceLabel" runat="server" Text='<%# ThousandSeperator(Decimal.Parse(Eval("Price").ToString())).ToString("N2") %>' /> <br /> </ItemTemplate> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> </asp:FormView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ChartDatabaseConnectionString %>" SelectCommand="SELECT * FROM [Product]"></asp:SqlDataSource> </div> </asp:Content>
NumberFormatFormView.aspx.cs (C# code file):
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class NumberFormatFormView : System.Web.UI.Page { private decimal number = 0.0M; protected void Page_Load(object sender, EventArgs e) { } public decimal ThousandSeperator(decimal Price) { number += Price; return Price; } }
[ 0 ] Comments