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

Format Grid Column

10 Answers 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ricardo Rekowsky
Top achievements
Rank 1
Ricardo Rekowsky asked on 12 Aug 2010, 08:18 PM
Hello!

I read through many documentation pages and also examples and looked up google to make one column formating work, but I didn't have any success so far.

I have a field to store a varchar(14) string called CNPJ.

I created a custom template for inserting/updating value and used RadMaskedTextBox for formating it and it works fine.
Now I wanted to format the display in the grid.

I already tried using GridBoundColumn, GridMaskedColumn, GridTemplateColumn and my last try was this one:

<telerik:GridTemplateColumn DataField="emp_cnpj" HeaderText="CNPJ" SortExpression="emp_cnpj"
                  UniqueName="emp_cnpj">
       <ItemTemplate>
                    <asp:label id="lblCNPJ" runat="server" text='<%# String.Format("{0:00.000.000/0000-00}", Eval("emp_cnpj")) %>' ></asp:label>
       </ItemTemplate>
</telerik:GridTemplateColumn>

I have a number stored as a string in the database as this one: 00000000000000 and need it to be formated as 00.000.000/0000-00.

For the registration date I used as follows:

<telerik:GridBoundColumn DataField="emp_dt_criacao" DataType="System.DateTime" HeaderText="Data Cadastro"
                    SortExpression="emp_dt_criacao" UniqueName="emp_dt_criacao" DataFormatString="{0:dd/MM/yyyy}">
                    <ItemStyle HorizontalAlign="Center" Width="80px" />
                </telerik:GridBoundColumn>

and it's perfectly fine, but I can neither apply a mask for the field mentioned above nor for a telephone field I have (also a varchar field)

Can anyone help me further, please?

Thanks!






10 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 12 Aug 2010, 09:35 PM
Hello Ricardo,

Using your label approach, try modifying your Eval statement to something like this: Convert.ToInt32(Eval("emp_cnpj")). That way the numeric format string you're using will hopefully work.

I hope that helps.
0
Ricardo Rekowsky
Top achievements
Rank 1
answered on 12 Aug 2010, 10:03 PM
Hello!

unfortunately it didn't work.

I changed the label to <asp:label id="lblCNPJ" runat="server" text='<%# String.Format("{0:00.000.000/0000-00}",  Convert.ToInt32(Eval("emp_cnpj"))) %>' ></asp:label>

and now I get an error as "The value was either too long or too short"...
I tried using Convert.ToInt64 but then the error changed to "Input string was not in a correct format".

Any other ideas?
0
Maria Ilieva
Telerik team
answered on 19 Aug 2010, 12:40 PM
Hello Ricardo,

Please try using the following:

<asp:label id="lblCNPJ" runat="server" text='<%# String.Format("{#:##.###.###/####-##}", Eval("emp_cnpj")) %>' ></asp:label>

Best wishes,
Maria Ilieva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ricardo Rekowsky
Top achievements
Rank 1
answered on 19 Aug 2010, 06:21 PM
thanks for the reply.

Now I get the following error: "Input string was not in a correct format."
0
Iana Tsolova
Telerik team
answered on 25 Aug 2010, 12:48 PM
Hello Ricardo,

Could you please confirm that the data passed to the label is applicable for the format grid you are setting?
It would be of help if you can send us a runnable sample/page so we can replicate the error and thus try finding a suitable way around.

Greetings,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rabeeh
Top achievements
Rank 2
answered on 10 Sep 2010, 05:34 PM
I would like to know if there is a quick way to set the date format of telerik GridDateTimeColumn, I want to format date columns when the grid is in display or select mode, I do not care to format date in Edit or Insert mode....

I tried setting  DataFormatString property for the GridDateTimeColumn, but did not work..
0
Iana Tsolova
Telerik team
answered on 13 Sep 2010, 12:05 PM
Hi Rabeeh,

Indeed, in order to change the data format of any column, the DataFormatString property is provided and should be used. Can you specify what is the format string you used and what was the unexpected result you observed?

Greetings,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rabeeh
Top achievements
Rank 2
answered on 14 Sep 2010, 09:10 AM
I used the DateTime format expressions, I do not remember the expression, but I want to display

1- Day / Month / Year
2- Year alone
3- Month / Year


Thank you in advanced

If you can help me, by giving me, the expression I need to set to get, the specified result...

Regards
0
Princy
Top achievements
Rank 2
answered on 14 Sep 2010, 10:06 AM
 Hello Rabeeh,

Set the DateFormatString of GridDateTimeColumn as "{0:dd/MM/yyyy}" to display date in Day / Month / Year format.
DataFormatString="{0:yyyy}" will dispaly only year and DataFormatString="{0:MM/yyyy}" will dispaly month and year.

Thanks,
Princy.
0
Rabeeh
Top achievements
Rank 2
answered on 14 Sep 2010, 10:08 AM
Thank you for the help, your effective at helping other

Tags
Grid
Asked by
Ricardo Rekowsky
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Ricardo Rekowsky
Top achievements
Rank 1
Maria Ilieva
Telerik team
Iana Tsolova
Telerik team
Rabeeh
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Share this question
or