DEV gridview 去除小数点后多余的零

  <dx:ASPxGridView ID="grid" OnCustomColumnDisplayText="grid_CustomColumnDisplayText"
        Settings-HorizontalScrollBarMode="Auto"
        SettingsBehavior-AllowSort="false"
        Styles-Cell-CssClass="textAlignLeft"
        ClientInstanceName="grid"
        Width="100%"
        runat="server"
        OnDataBound="grid_DataBound"
        DataSourceID="NorthwindDataSource" >
        <SettingsBehavior ColumnResizeMode="Control" AllowEllipsisInText="true"  />
    </dx:ASPxGridView> 

protected void grid_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e)

    {
        if (e.Column.FieldName == "UnitPrice")
        { 
            string[] strSplit = e.Value.ToString().Split('.');
            string str = strSplit[1].TrimEnd('0');
            e.DisplayText = str == "" ? strSplit[0] : strSplit[0] + "." + str;
            
        }
    }

猜你喜欢

转载自blog.csdn.net/liangyaomu/article/details/81061308