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

How to format columns in DetailTable in vb?

2 Answers 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 03 Dec 2008, 08:34 AM
I have to format columns in my RadGrids based on user-selected formatting, so I can't always format columns in the aspx page, I have to do it in the code behind.

With that in mind, I have a couple of helper functions which I use to format columns in a RadGrid

However, I'm not sure what the best way would be to format columns in a DetailTable. Could someone let me know if this is the best way of achieving this?


Public Shared Sub RadGridColumnFormatDate(ByRef RadGrid1 As RadGrid, ByVal ColumnName As String)
            Dim col As GridBoundColumn

            For Each detailtable In RadGrid1.MasterTableView.DetailTables
                Try
                    col = detailtable.Columns.FindByUniqueName(ColumnName)
                    col.DataFormatString = "{0:" & GetDateFormatStr & "}"
                Catch
                End Try
            Next

            Try
                col = RadGrid1.Columns.FindByUniqueName(ColumnName)
                col.DataFormatString = "{0:" & GetDateFormatStr & "}"
            Catch
            End Try
        End Sub

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Dec 2008, 10:00 AM
Hi Rick,

I applied DataFormatString for the DetailTable Column as shown below. Set the Name property for the Detail table

ASPX:
                      <DetailTables>  
                      <telerik:GridTableView runat="server" Caption="Detail" Name="Detail"  DataSourceID="SqlDataSource1" >  
                       <Columns>  
                         <telerik:GridBoundColumn  HeaderText="EndDate"   UniqueName="EndDate" DataField="EndDate"  ></telerik:GridBoundColumn>  
                       </Columns>  
                      </telerik:GridTableView>  
                    </DetailTables>  
                

CS:
Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) 
         
         For Each item As GridDataItem In RadGrid1.Items 
             If item.OwnerTableView.Name = "Detail" Then 
                 Dim childtable As GridTableView = DirectCast(item.OwnerTableView, GridTableView) 
                For Each col As GridColumn In childtable.RenderColumns 
                     If (col.UniqueName = "EndDate") Then 
                         Dim boundCol As GridBoundColumn = DirectCast(col, GridBoundColumn) 
                         Dim getFormat As String = "d" 
                         boundCol.DataFormatString = "{0:" & getFormat & "}" 
                     End If 
                 Next 
                 childtable.Rebind() 
             End If 
        Next 
     End Sub 
 

Shinu.
0
Rick
Top achievements
Rank 1
answered on 03 Dec 2008, 01:45 PM
Hi Shinu,

Thanks for that code sample, i'll keep it in mind
Tags
Grid
Asked by
Rick
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Rick
Top achievements
Rank 1
Share this question
or