1

I want to show only 2 decimal places in gridview column. column name is InsuaranceAmount,TotalAmount and TravelAssistAmoun.

for (int i = 0; i < bookingDetailsEmailRS.Length - 1; i++)
 {
BookingDetailsEmailRS[] bookingDetailsEmailRS = b.GetBookingDetails(soap, emailid, out    errorCode, out  errorAtNode);
 GridView1.DataSource = bookingDetailsEmailRS.Select(obj => new
        {
            TravelerName = obj.Travelers[0].FirstName + obj.Travelers[0].MiddleName + obj.Travelers[0].LastName,
            obj.BookingNumber,
            obj.BookingStatus,
            obj.ContactNumber,
            obj.CouponDiscountAmount,
            obj.DepartureDate,
            obj.FromCity,
            obj.ToCity,
            obj.PaidAmount,
            obj.TicketType,
            obj.InsuaranceAmount,
            obj.TotalAmount,
            obj.TravelAssistAmount
        }).ToList();


        GridView1.DataBind();    
 }

In this variable bookingDetailsEmailRS, I got the response.

Anurag Jain
  • 1,371
  • 4
  • 23
  • 34

3 Answers3

6

Use DataFormat property :

<asp:BoundField DataField="InsuaranceAmount" HeaderText="Total Data"  
     ReadOnly="True" SortExpression="totaldata" DataFormatString="{0:0.00}" />

For the second part of your question use Eval method's second parameter to format your data :

<%# Eval("InsuaranceAmount", "{0:0.00}") %>

This might also be helpful

Silagy
  • 3,053
  • 2
  • 27
  • 39
2

The Eval function has two parameters, the first is the Bindable field and the second is a format for the field. Use something like {0:0.00} in this portion of the control's fields definition.

Paul
  • 4,160
  • 3
  • 30
  • 56
1

In case of bound columns, you have a DataFormatString attribute. You could do something like to show only 2 decimal places in gridview column:

DataFormatString="{0:0.00}"

Ex:

<asp:BoundField DataField="TotalAmount" HeaderText="Total Amount" DataFormatString="{0:0.00}" />

Reference: Numeric Custom Format Strings

palaѕн
  • 72,112
  • 17
  • 116
  • 136