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

Advanced Data Binding Data Formatting

2 Answers 11 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 15 Jul 2014, 02:41 PM
Dear All,

I'm using

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            RadGrid1.DataSource = GridDataSource;            
        }


to bind the grid, and in the front page (aspx) it's like

<telerik:RadGrid ID="RadGrid1" runat="server" MasterTableView-CommandItemDisplay="Top" OnNeedDataSource="RadGrid1_NeedDataSource" AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True" ShowGroupPanel="True" PageSize="20" Skin="WebBlue">
                        <ClientSettings AllowDragToGroup="True">
                            <Scrolling AllowScroll="True" UseStaticHeaders="True"></Scrolling>
                        </ClientSettings>
                    </telerik:RadGrid>

I'd just like to ask how can I set the dataformatstring = "{0:d}" to certain columns for example?

Thanks

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 16 Jul 2014, 06:28 AM
Hi Tim,

I guess you are having AutoGeneratedColumns in your grid. Please try the following code snippet to set DataFormatString for columns according to their type.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
  foreach(GridColumn column in RadGrid1.MasterTableView.AutoGeneratedColumns)
  {
    //To set format for DateTime column
    if (column.ColumnType == "GridDateTimeColumn")
    {
     (column as GridDateTimeColumn).DataFormatString = "{0:d}";
    }          
  }
  RadGrid1.Rebind();
}

Thanks,
Princy
0
Tim
Top achievements
Rank 1
answered on 16 Jul 2014, 09:51 AM
Thank you very much Princy that's the solution.
Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Tim
Top achievements
Rank 1
Share this question
or