DataFormatString for RadGrid

10 posts, 0 answers
  1. Padmaja
    Padmaja avatar
    12 posts
    Member since:
    Dec 2008

    Posted 17 Mar 2010 Link to this post

    Hi Telerik Support,

    I want to extract telerik DataFormatString into Skins.

    The below code is the on ei declare in the Skin

    My Skin Code :

    <%@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="radG" %>

     <radG:RadGrid runat="server" SkinID="myGrid" Skin="Grid" SkinsPath="~/App_Themes/Default/" DataFormatString="{0:dd/MM/yyyy}">
            <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="True" />          
    </radG:RadGrid>

    My Web Page Code

     <radG:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"
                                SkinID="myGrid" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
                                AllowAutomaticUpdates="True" AllowPaging="True" AllowSorting="True" LoadingTemplateTransparency="50"
                                AllowFilteringByColumn="True" BackColor="Transparent" Width="100%">                           
                 <MasterTableView DataKeyNames="UserName" >                                                        
                     <Columns>                                   
                             <radG:GridBoundColumn HeaderText="User Name" DataField ="displayUserName" meta:resourcekey="BoundFieldResource1"></radG:GridBoundColumn> 
                      </Columns>                                                    
                 </MasterTableView>
                 <FilterMenu CssClass="FilterMenuClass1"></FilterMenu>
            </radG:RadGrid> 

    When I bind Date to GridBoundColumns inside my web pages it's not formating what I declared in my skin " MyGrid ". Please let me know how can i extract this DataFormatString DateTime Grid Bound Columns.

  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 22 Mar 2010 Link to this post

    Hello Padmaja,

    The DataFormatString property is property of the grid columns. Therefore if you want to move it in the Skin file, you will need to move the grid columns definition there as well. So in the Skin file you should heve the below:

    <radG:RadGrid runat="server" SkinID="myGrid" Skin="Grid" SkinsPath="~/App_Themes/Default/">
        <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="True" /> 
        <MasterTableView>                                                         
            <Columns>                                    
                <radG:GridBoundColumn HeaderText="User Name" 
                    DataField ="displayUserName" 
                    meta:resourcekey="BoundFieldResource1"
                    DataFormatString="{0:dd/MM/yyyy}"></radG:GridBoundColumn>  
             </Columns>                                                    
         </MasterTableView>          
    </radG:RadGrid>


    All the best,
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Anzar
    Anzar avatar
    62 posts
    Member since:
    Sep 2012

    Posted 22 Nov 2012 Link to this post

    HI,
    How to set dataformat string from a session variable on aspx page.

    Thanks & Regards
    Anzar.M
  5. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 26 Nov 2012 Link to this post

    Hi Anzar,

    You could use the following approach:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string dataFormatString = "{0:d}";
            Session["DataFormatString"] = dataFormatString;
        }
    }
    protected void RadGrid1_DataBinding(object sender, EventArgs e)
    {
        GridDateTimeColumn dateTimeColumn = RadGrid1.MasterTableView.GetColumnSafe("OrderDate") as GridDateTimeColumn;
        dateTimeColumn.DataFormatString = (string)Session["DataFormatString"];
    }

    I hope this will prove helpful. Please give it a try and let me know about the result.

    Greetings,
    Eyup
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Anish
    Anish avatar
    4 posts
    Member since:
    Jan 2013

    Posted 21 Aug 2013 Link to this post

    Hi Eyup 

    It's working  in item databound but how to set the same in aspx page (<telerik:GridDateTimeColumn DataFormatString=" ">  </telerik:GridDateTimeColumn> )

    for eg: in Template Coloumn we can use like mentioned below:

     <ItemTemplate>
     <xxx:xxxLabel runat="server" ID="dateFrom" Text='<%# Eval("VALID_FROM", String.Format("{{0:{0}}}",      ShipmateUtilities.UtilityLayer.SessionEx.UserDateFormat))  %>'>
     </xxx:xxxLabel>
     </ItemTemplate>

    how to use the same in GridDateTimeColumn?


    Thanks&regards
    Anish Sethu
                         
  7. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 23 Aug 2013 Link to this post

    Hello Anish,

    Please note that the DataFormatString cannot be set dynamically on the ASPX page, however, you can set it using the following effective and convenient approach:
    Copy Code
    protected void RadGrid1_DataBinding(object sender, EventArgs e)
    {
        foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
        {
            if (col is GridDateTimeColumn)
            {
                ((GridDateTimeColumn)col).DataFormatString = "{0:yyyy MM}";
            }
        }
    }

    Hope this helps.

    Regards,
    Eyup
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  8. Quake
    Quake avatar
    7 posts
    Member since:
    Aug 2013

    Posted 29 Aug 2013 Link to this post

    please update, MasterTableView doesn't exist anymore.
  9. Quake
    Quake avatar
    7 posts
    Member since:
    Aug 2013

    Posted 29 Aug 2013 Link to this post

    ok this seems to work as of 8/29/2013:

     

    private void RadDataGrid1_DataBindingComplete(object sender, Telerik.UI.Xaml.Controls.Grid.DataBindingCompleteEventArgs e)
    {
        foreach (DataGridColumn col in RadDataGrid1.Columns)
        {
     
            if (col is DataGridDateColumn)
            {
     
                ((DataGridDateColumn)col).CellContentFormat = "{0:yyyy MM}";
     
            }
     
        }
    }
  10. Quake
    Quake avatar
    7 posts
    Member since:
    Aug 2013

    Posted 30 Aug 2013 Link to this post

    Problem:  After applying a Filter to a DateTime column, the column simply disappears never to return.  This is different from the behavior of all other datatype columns, which get a blue underline instead.  Bug?  I see no unhandled exceptions in the trace.
  11. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 04 Sep 2013 Link to this post

    Hi Quake,

    Can you please share whether you are using RadGrid for ASP.NET AJAX or XAML RadDataGrid?
    Looking forward to your reply.

    Regards,
    Eyup
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017