DataFormatString for RadGrid

1 Answer 6556 Views
Grid
Padmaja
Top achievements
Rank 1
Padmaja asked on 17 Mar 2010, 08:54 AM
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.

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 22 Mar 2010, 12:56 PM
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.
Anzar
Top achievements
Rank 2
commented on 22 Nov 2012, 06:25 AM

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

Thanks & Regards
Anzar.M
Eyup
Telerik team
commented on 26 Nov 2012, 11:20 AM

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.
Anish
Top achievements
Rank 1
commented on 21 Aug 2013, 06:01 AM

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
                     
Eyup
Telerik team
commented on 23 Aug 2013, 11:28 AM

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.
Quake
Top achievements
Rank 1
commented on 30 Aug 2013, 02:14 AM

please update, MasterTableView doesn't exist anymore.
Quake
Top achievements
Rank 1
commented on 30 Aug 2013, 02:43 AM

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}";
 
        }
 
    }
}
Quake
Top achievements
Rank 1
commented on 30 Aug 2013, 08:56 PM

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.
Eyup
Telerik team
commented on 04 Sep 2013, 07:54 AM

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.
Tags
Grid
Asked by
Padmaja
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or