Click here to Skip to main content
15,905,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all,


I have a grid view where i am binding the value of price and tax and i want to show them upto two digits after decimal..

.aspx code:-

XML
<asp:GridView runat="server" AllowPaging="True" AlternatingRowStyle-CssClass="alt"
        CellPadding="4" CellSpacing="2" CssClass="mGrid"
        EmptyDataText="There is no Item in your Cart" ForeColor="Black"
                                GridLines="None" ID="Grid1"
        AutoGenerateColumns="False" DataKeyNames="pid"
        onrowcancelingedit="Grid1_RowCancelingEdit"
        onrowdeleting="Grid1_RowDeleting" PagerStyle-CssClass="pgr" ShowFooter="True"
                                Width="100%" onrowediting="Grid1_RowEditing"
        onrowupdating="Grid1_RowUpdating"
        onpageindexchanging="Grid1_PageIndexChanging"
        onrowdatabound="Grid1_RowDataBound">
                                <RowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Product ID">
<ItemTemplate>
<asp:Label runat="server" ID="lblpid" Text='<%#Eval("PID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label runat="server" ID="lblname" Text='<%#Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:Label runat="server" ID="lblquantity" Text='<%#Eval("Quantity") %>'></asp:Label>
&nbsp; &nbsp;
<asp:LinkButton runat="server" ID="linkedit" CommandName="Edit" Text="Edit" Font-Underline="false"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtquantity" Text='<%#Eval("Quantity") %>'></asp:TextBox>
&nbsp;&nbsp;
<asp:LinkButton runat="server" ID="linkupdate" CommandName="Update" Text="Update"></asp:LinkButton>
&nbsp;
<asp:LinkButton runat="server" ID="linkcancel" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Price">
<ItemTemplate>
<asp:Label runat="server" ID="lblprice" Text='<%#Eval("UnitPrice") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tax">
<ItemTemplate>
<asp:Label runat="server" ID="lbltax" Text='<%#Eval("Tax") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total">
<ItemTemplate>
<asp:Label runat="server" ID="lkbltotalprice" Text='<%# Eval("TotalPrice") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" ID="linkdlt" CommandName="Delete"><asp:Image runat="server" ImageUrl="~/WebSiteImages/delete_button.gif" /></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
                                <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
                                <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                                <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                                <AlternatingRowStyle CssClass="alt" />
</asp:GridView>



kindly suggest me any solution to format it in eval function...
Posted

hi dear

use displayformat = "{0}:2D" in Gridview colum

thanks
 
Share this answer
 
Comments
abhishekagrwl25 22-May-12 3:09am    
but how to set displayformat in GridView column.??
use:


HTML
<% # Eval("Amount","{0:#0.00}") %>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900