Format Grid Column

11 posts, 0 answers
  1. Ricardo Rekowsky
    Ricardo Rekowsky avatar
    9 posts
    Member since:
    Oct 2009

    Posted 12 Aug 2010 Link to this post

    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!






  2. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 12 Aug 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ricardo Rekowsky
    Ricardo Rekowsky avatar
    9 posts
    Member since:
    Oct 2009

    Posted 12 Aug 2010 Link to this post

    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?
  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 19 Aug 2010 Link to this post

    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
  6. Ricardo Rekowsky
    Ricardo Rekowsky avatar
    9 posts
    Member since:
    Oct 2009

    Posted 19 Aug 2010 Link to this post

    thanks for the reply.

    Now I get the following error: "Input string was not in a correct format."
  7. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 25 Aug 2010 Link to this post

    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
  8. Rabeeh
    Rabeeh  avatar
    62 posts
    Member since:
    Sep 2007

    Posted 10 Sep 2010 Link to this post

    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..
  9. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 13 Sep 2010 Link to this post

    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
  10. Rabeeh
    Rabeeh  avatar
    62 posts
    Member since:
    Sep 2007

    Posted 14 Sep 2010 Link to this post

    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
  11. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Sep 2010 Link to this post

     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.
  12. Rabeeh
    Rabeeh  avatar
    62 posts
    Member since:
    Sep 2007

    Posted 14 Sep 2010 Link to this post

    Thank you for the help, your effective at helping other

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017