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

how to reach grid columns after setting datasource

1 Answer 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nazim
Top achievements
Rank 1
Nazim asked on 07 Jan 2011, 02:03 PM
I am getting follwing error when I try to get grid columns after setting data soure a table which AutoGenerateColumns property is true.  The bold line throws an exception whit message "Cannot find column bound to field 'date" even  the datatable has that column. I thought that may be a problem with rendering such it is not populated yet. Then I put that code in the columns created event and also pre render event. Result has not changed yet. Is there anyone faced tihs problem before?
Thnaks,


telerik:RadGrid ID="rgridDeliveryDate" skin="Mar"
              Width="100%" AutoGenerateColumns="true" AllowMultiRowSelection="True"           
              runat="server" Gridlines="None" EnableEmbeddedSkins="false">                
              <ClientSettings EnableRowHoverStyle="true">                  
                <Selecting AllowRowSelect="True"></Selecting>
                <Resizing AllowRowResize="True" EnableRealTimeResize="True" ResizeGridOnColumnResize="True"
                    AllowColumnResize="True"></Resizing>
              </ClientSettings>
           <MasterTableView Width="100%" Summary="" NoMasterRecordsText="Servis saatleri set edilmemis" >    
             
           </MasterTableView>           
        </telerik:RadGrid>

code behind
DataTable dt = mh.GetServicePeriods();
rgridDeliveryDate.PreRender += new EventHandler(rgridDeliveryDate_PreRender);
rgridDeliveryDate.DataSource = dt;
rgridDeliveryDate.DataBind();

GridBoundColumn grdCol = rgridDeliveryDate.Columns.FindByDataField("date") as GridBoundColumn;
grdCol.DataFormatString = "dd/MM/yyyy";
grdCol.HeaderText = "";



1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 07 Jan 2011, 02:44 PM
Hi Nazim,

You can customize the properties of auto-generated columns at runtime by providing a handler for the grid's ColumnCreated event. In the event handler, cast the column to the appropriate type and set its attributes. You can review the following help article for more information:
http://www.telerik.com/help/aspnet-ajax/grdusingcolumns.html

Greetings,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Nazim
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or