This is a migrated thread and some comments may be shown as answers.

get decimal numbers of auto-generated columns

4 Answers 214 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marcelo
Top achievements
Rank 1
Marcelo asked on 07 Jan 2011, 10:55 PM
Hi.
I'm sure is very simple but I'm lost at this point.

I have a RadGrid with automatic generation of columns, this RadGrid has several sources of data therefore do not know the types of data displayed in the radgrid, but the RadGrid must have the ability to edit your rows and use the UpdateCommand method within which gets the values of the fields, but when a field has a decimal value (i.e. -0.326267) always returns only with two decimales (i.e.  -0.32)
How do I retrieve the number with all decimals?

P.D. Sorry for my English

4 Answers, 1 is accepted

Sort by
0
Mike Nogen
Top achievements
Rank 1
answered on 08 Jan 2011, 12:07 AM
Hello!

Try use the DateFormatString property of the Column. The example below should display 8 digits.

DataFormatString

 

="{0:f8}"

Used like like this.

 

protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
       {
           if (e.Column.UniqueName == "Price")
               {
                   GridBoundColumn boundColumn = e.Column as GridBoundColumn;
                   boundColumn.DataFormatString = "{0:f8}";
               }
       }



/M




0
Marcelo
Top achievements
Rank 1
answered on 08 Jan 2011, 10:12 PM
Hi Mike, thanks for answering

Your code is correct and it works great if you know the UniqueName, in my case is not so because bdd tables must be created by the user according to their needs.
Now I have another question, taking as a starting point the code indicated that displays 8 digits, these numbers are always rounded in the radgrid. How do I disable this property?
0
Accepted
Mike Nogen
Top achievements
Rank 1
answered on 09 Jan 2011, 01:10 AM
"do not know the types of data displayed "
On every item in the Grid you have a property called "DataType". I´m sure that you can use that. So instead of looking on the Unique name do it like

if (e.Column.DataType instead.


But maybe I haven´t understood your issue yet beacuse by default my grid shows what´s in the database.If I have 0,940758293838863 in the datbase then it´s outputted like that also in the grid.

Is your problem just in the situation where you make an "edit/update" or if you manually enter this 0,940758293838863 in you database it will be outputted like 0,94 ?

Which DataTypes in the database are you using where you get this issue?

/M
0
Marcelo
Top achievements
Rank 1
answered on 10 Jan 2011, 09:24 PM
great idea, thanks a lot
finally my code was as follows:

protected void RadGrid3_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
 {
        switch (e.Column.DataTypeName)
        {
              case "System.Double":
                        GridNumericColumn numericColumn_0 = e.Column as GridNumericColumn;
                        numericColumn_0.DataFormatString = "{0:F15}";
                        numericColumn_0.KeepNotRoundedValue = true;
                        break;
              case "System.Decimal":
                        GridNumericColumn numericColumn_1 = e.Column as GridNumericColumn;
                        numericColumn_1.DataFormatString = "{0:D8}";
                        numericColumn_1.KeepNotRoundedValue = true;
                        break;
              case "System.Int32":
                        GridBoundColumn boundColumn_0 = e.Column as GridBoundColumn;
                        boundColumn_0.DataFormatString = "{0:N}";
                        break;
              case "System.Int64":
                        GridBoundColumn boundColumn_1 = e.Column as GridBoundColumn;
                        boundColumn_1.DataFormatString = "{0:N}";
                        break;
       }
}
Tags
Grid
Asked by
Marcelo
Top achievements
Rank 1
Answers by
Mike Nogen
Top achievements
Rank 1
Marcelo
Top achievements
Rank 1
Share this question
or