Link to home
Start Free TrialLog in
Avatar of fm250
fm250Flag for United States of America

asked on

gridview sting format string from double

I have field bound datatype is varchar, but stored into it is double [85.321456]
I want to display it as (85.32) . and there are some null fields.  thanks
Avatar of rajvja
rajvja
Flag of United Kingdom of Great Britain and Northern Ireland image

In the gridview rowdatabound event,

Protected Sub gvwRow_Databound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then

            Dim idx As Integer = e.Row.RowIndex
            e.Row.Cells(yourcolindex).text   = formatnumber(cdbl( e.Row.Cells(yourcolindex).text),2)
    End Sub
Avatar of fm250

ASKER

Oops,  I am using C#
thanks
Avatar of fm250

ASKER

Also the field is string but contain double no.
Protected void gvwRow_Databound(Object sender, GridViewRowEventArgs e)
{
        If e.Row.RowType = DataControlRowType.DataRow
        {

            int idx = e.Row.RowIndex;
            e.Row.Cells(yourcolindex).text   = formatnumber(Convert.ToDouble(e.Row.Cells(yourcolindex).text),2)
        }
}
Avatar of fm250

ASKER

here is the correct format with c# but formatnumber is not known.
if (e.Row.RowType == DataControlRowType.DataRow )
{
int idx = e.Row.RowIndex;
e.Row.Cells[5].Text = formatnumber(Convert.ToDouble(e.Row.Cells[5].Text),2)
}
ASKER CERTIFIED SOLUTION
Avatar of rajvja
rajvja
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial