5 Answers, 1 is accepted
0
Schlurk
Top achievements
Rank 2
answered on 14 Dec 2009, 09:47 PM
This depends on what kind of columns you have, but as long as the type of column supports a DataFormatString all you simply have to do would be to get an instance of the column's object, and then do .DataFormatString. Some columns do not support this, and you would have to check for proper casts etc.
0
Larry
Top achievements
Rank 1
answered on 14 Dec 2009, 09:56 PM
Thank you for your reply. I know I have to get an instance of the column's object and set the DataFormatString . But how do I do that?
I've tried the following...
With no luck...
I can't access GridBoundColumn. It says my type is GridExpandColumn (test = GridExpandColumn)
Not sure what the heck.
I've tried the following...
| Protected Sub RadGrid2_ColumnCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles RadGrid2.ColumnCreated |
| Dim test As String = e.Column.ColumnType |
| If (e.Column.ColumnType = "GridBoundColumn") Then |
| Dim bndcol As GridBoundColumn = DirectCast(e.Column, GridBoundColumn) |
| bndcol.DataFormatString = "" |
| End If |
| End Sub |
| Protected Sub RadGrid2_ColumnCreating(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridColumnCreatingEventArgs) Handles RadGrid2.ColumnCreating |
| Dim test As String = e.Column.ColumnType |
| 'If (e.Column.ColumnType = "GridBoundColumn") Then |
| Dim bndcol As GridBoundColumn = DirectCast(e.Column, GridBoundColumn) |
| bndcol.DataFormatString = "" |
| 'End If |
| End Sub |
I can't access GridBoundColumn. It says my type is GridExpandColumn (test = GridExpandColumn)
Not sure what the heck.
| <telerik:RadGrid ID="RadGrid3" runat="server" Width="100%" ShowStatusBar="True" AutoGenerateColumns="False" |
| ShowFooter="True" GridLines="Horizontal" AllowSorting="True" OnDetailTableDataBind="RadGrid3_DetailTableDataBind" |
| Skin="Web20" HorizontalAlign="Right"> |
| <MasterTableView Width="100%" ClientDataKeyNames="GROUP" DataKeyNames="GROUP" Name="Master"> |
| <DetailTables> |
| <telerik:GridTableView DataKeyNames="DESCRIPTION" Name="Sub" Width="100%" ItemStyle-HorizontalAlign="Left"> |
| <Columns> |
| <telerik:GridBoundColumn DataField="DESCRIPTION" HeaderText="DESCRIPTION" SortExpression="DESCRIPTION" |
| UniqueName="DESCRIPTION"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Jan" DataType="System.Decimal" HeaderText="Jan" |
| ReadOnly="True" SortExpression="Jan" UniqueName="Jan" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Feb" DataType="System.Decimal" HeaderText="Feb" |
| ReadOnly="True" SortExpression="Feb" UniqueName="Feb" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Mar" DataType="System.Decimal" HeaderText="Mar" |
| ReadOnly="True" SortExpression="Mar" UniqueName="Mar" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Apr" DataType="System.Decimal" HeaderText="Apr" |
| ReadOnly="True" SortExpression="Apr" UniqueName="Apr" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="May" DataType="System.Decimal" HeaderText="May" |
| ReadOnly="True" SortExpression="May" UniqueName="May" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Jun" DataType="System.Decimal" HeaderText="Jun" |
| ReadOnly="True" SortExpression="Jun" UniqueName="Jun" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Jul" DataType="System.Decimal" HeaderText="Jul" |
| ReadOnly="True" SortExpression="Jul" UniqueName="Jul" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Aug" DataType="System.Decimal" HeaderText="Aug" |
| ReadOnly="True" SortExpression="Aug" UniqueName="Aug" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Sep" DataType="System.Decimal" HeaderText="Sep" |
| ReadOnly="True" SortExpression="Sep" UniqueName="Sep" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Oct" DataType="System.Decimal" HeaderText="Oct" |
| ReadOnly="True" SortExpression="Oct" UniqueName="Oct" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Nov" DataType="System.Decimal" HeaderText="Nov" |
| ReadOnly="True" SortExpression="Nov" UniqueName="Nov" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Dec" DataType="System.Decimal" HeaderText="Dec" |
| ReadOnly="True" SortExpression="Dec" UniqueName="Dec" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Year Total" DataType="System.Decimal" HeaderText="Year Total" |
| ReadOnly="True" SortExpression="Year Total" UniqueName="Year Total" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| </telerik:GridTableView> |
| </DetailTables> |
| <ExpandCollapseColumn Visible="True"> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridBoundColumn DataField="GROUP" HeaderText="GROUP" SortExpression="GROUP" |
| UniqueName="GROUP"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Jan" DataType="System.Decimal" HeaderText="Jan" |
| ReadOnly="True" SortExpression="Jan" UniqueName="Jan" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Feb" DataType="System.Decimal" HeaderText="Feb" |
| ReadOnly="True" SortExpression="Feb" UniqueName="Feb" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Mar" DataType="System.Decimal" HeaderText="Mar" |
| ReadOnly="True" SortExpression="Mar" UniqueName="Mar" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Apr" DataType="System.Decimal" HeaderText="Apr" |
| ReadOnly="True" SortExpression="Apr" UniqueName="Apr" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="May" DataType="System.Decimal" HeaderText="May" |
| ReadOnly="True" SortExpression="May" UniqueName="May" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Jun" DataType="System.Decimal" HeaderText="Jun" |
| ReadOnly="True" SortExpression="Jun" UniqueName="Jun" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Jul" DataType="System.Decimal" HeaderText="Jul" |
| ReadOnly="True" SortExpression="Jul" UniqueName="Jul" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Aug" DataType="System.Decimal" HeaderText="Aug" |
| ReadOnly="True" SortExpression="Aug" UniqueName="Aug" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Sep" DataType="System.Decimal" HeaderText="Sep" |
| ReadOnly="True" SortExpression="Sep" UniqueName="Sep" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Oct" DataType="System.Decimal" HeaderText="Oct" |
| ReadOnly="True" SortExpression="Oct" UniqueName="Oct" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Nov" DataType="System.Decimal" HeaderText="Nov" |
| ReadOnly="True" SortExpression="Nov" UniqueName="Nov" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Dec" DataType="System.Decimal" HeaderText="Dec" |
| ReadOnly="True" SortExpression="Dec" UniqueName="Dec" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Year Total" DataType="System.Decimal" HeaderText="Year Total" |
| ReadOnly="True" SortExpression="Year Total" UniqueName="Year Total" DataFormatString="{0:$#,##0.00;($#,##0.00);.}"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| </MasterTableView> |
| <ClientSettings ReorderColumnsOnClient="True" AllowColumnsReorder="True"> |
| <Selecting AllowRowSelect="True"></Selecting> |
| </ClientSettings> |
| </telerik:RadGrid> |
0
Schlurk
Top achievements
Rank 2
answered on 15 Dec 2009, 03:03 PM
Have you tried to, instead of looking at the column type, use the UniqueName property to identify the columns? This would be a better alternative than to look for the column type.
0
Larry
Top achievements
Rank 1
answered on 15 Dec 2009, 05:59 PM
As you may have noticed that would be very inefficient way of doing this because it is unique. I would have to use a case statement and set every unique id. However, When I use UniqueName or ColumnType the results for every column is "GridExpandColumn".
????
TELERIK is this a bug?
The results of both UniqueName and ColumnType = "GridExpandColumn". Why?
????
| Protected Sub RadGrid2_ColumnCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles RadGrid2.ColumnCreated |
| Dim test As String = e.Column.UniqueName |
| If (e.Column.UniqueName = "Jan") Then |
| Dim bndcol As GridBoundColumn = DirectCast(e.Column, GridBoundColumn) |
| bndcol.DataFormatString = "" |
| End If |
| End Sub |
TELERIK is this a bug?
The results of both UniqueName and ColumnType = "GridExpandColumn". Why?
0
Hello Larry,
Best regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
The OnColumnCreated server event of RadGrid for ASP.NET AJAX is raised for structure columns (GridExpandColumn, GridGroupSplitterColumn, etc.) and auto-generated columns. In case you have declaratively defined columns in the grid markup, you can customize them intercepting the PreRender event of the control as illustrated in the bottom section of this article.
Best regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.