Dear Telerik team,
i have a grid with some extra icon column (GridImageColumn). The value of this column is in another column from db. I make it visible = false from server code.
When i export the grid in Excel (
i want to show on excel the value of the column (db column) and not the icon column.
Thank you in advance for your time.
I Use:
VS 2008 (VB)
Telerik 2011.3.1305.35
Below is the client and server code.
Server:
i have a grid with some extra icon column (GridImageColumn). The value of this column is in another column from db. I make it visible = false from server code.
When i export the grid in Excel (
ExportOnlyData =
True
), i cannot see the value of the GridImageColumni want to show on excel the value of the column (db column) and not the icon column.
Thank you in advance for your time.
I Use:
VS 2008 (VB)
Telerik 2011.3.1305.35
Below is the client and server code.
<
telerik:RadGrid
ID
=
"grdPPCOrders"
runat
=
"server"
Height
=
"300px"
Skin
=
"Windows7"
AllowMultiRowSelection
=
"true"
>
<
HeaderContextMenu
CssClass
=
""
>
</
HeaderContextMenu
>
<
MasterTableView
DataKeyNames
=
"ID"
>
<
Columns
>
<
telerik:GridClientSelectColumn
UniqueName
=
"Selected"
HeaderStyle-Width
=
"30"
>
<
HeaderStyle
Width
=
"30px"
></
HeaderStyle
>
</
telerik:GridClientSelectColumn
>
<
telerik:GridImageColumn
UniqueName
=
"CardTypeImage"
HeaderStyle-Width
=
"30"
>
<
HeaderStyle
Width
=
"30px"
></
HeaderStyle
>
</
telerik:GridImageColumn
>
<
telerik:GridImageColumn
UniqueName
=
"OrderStatusImage"
HeaderStyle-Width
=
"30"
>
<
HeaderStyle
Width
=
"30px"
></
HeaderStyle
>
</
telerik:GridImageColumn
>
<
telerik:GridImageColumn
UniqueName
=
"HasCreditNoteImage"
HeaderStyle-Width
=
"30"
>
<
HeaderStyle
Width
=
"30px"
></
HeaderStyle
>
</
telerik:GridImageColumn
>
<
telerik:GridBoundColumn
FilterControlWidth
=
"105px"
DataField
=
"ID"
HeaderText
=
"ID"
SortExpression
=
"ID"
UniqueName
=
"ID2"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"Contains"
ShowFilterIcon
=
"false"
ItemStyle-Width
=
"50"
HeaderStyle-Width
=
"50"
>
<
HeaderStyle
Width
=
"50px"
></
HeaderStyle
>
<
ItemStyle
Width
=
"50px"
></
ItemStyle
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
CommandItemSettings
ShowExportToExcelButton
=
"true"
ShowAddNewRecordButton
=
"false"
/>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
>
</
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
ClientSettings
AllowKeyboardNavigation
=
"true"
EnablePostBackOnRowClick
=
"true"
EnableRowHoverStyle
=
"True"
>
<
Selecting
AllowRowSelect
=
"True"
EnableDragToSelectRows
=
"False"
/>
<
ClientEvents
/>
<
Scrolling
AllowScroll
=
"true"
UseStaticHeaders
=
"True"
SaveScrollPosition
=
"True"
/>
<
Resizing
AllowColumnResize
=
"True"
AllowResizeToFit
=
"True"
EnableRealTimeResize
=
"True"
/>
</
ClientSettings
>
<
FilterMenu
EnableImageSprites
=
"False"
>
</
FilterMenu
>
</
telerik:RadGrid
>
Server:
Protected
Sub
btnExportExcel_Click(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
btnExportExcel.Click
grdPPCOrders.ExportSettings.ExportOnlyData =
True
'grdPPCOrders.MasterTableView.Columns.Item(0).Visible = False
'grdPPCOrders.MasterTableView.Columns.FindByDataField("CardType").Visible = True !ERROR Cannot find column bound to field
'grdPPCOrders.Columns.FindByDataField("CardType").Visible = True !ERROR Cannot find column bound to field
'grdPPCOrders.MasterTableView.Columns.Item(9).Visible = True
grdPPCOrders.MasterTableView.ExportToExcel()
End
Sub
Protected
Sub
grdPPCOrders_ColumnCreated(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridColumnCreatedEventArgs)
Handles
grdPPCOrders.ColumnCreated
Select
Case
e.Column.UniqueName
Case
"Notes"
,
"ID"
,
"SupplierID_CustomerID"
,
"VesselID"
,
"OrderStatus"
,
"CardType"
,
"HasCreditNote"
,
"InvoiceDate"
,
"Price"
,
"NetProfit"
Dim
boundColumn
As
GridBoundColumn =
CType
(e.Column, GridBoundColumn)
boundColumn.Visible =
False
End
Select
End
Sub
Protected
Sub
grdPPCOrders_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridItemEventArgs)
Handles
grdPPCOrders.ItemDataBound
'Dim SelectedColumn(GridColumns.Count) As String
If
TypeOf
e.Item
Is
GridHeaderItem
Then
Dim
header
As
GridHeaderItem =
DirectCast
(e.Item, GridHeaderItem)
'header("OrderStatus").Text = ""
'header("HasCreditNote").Text = ""
End
If
If
TypeOf
e.Item
Is
GridDataItem
Then
Dim
dataItem
As
GridDataItem =
CType
(e.Item, GridDataItem)
Dim
CardTypeColumn
As
String
= dataItem(
"CardType"
).Text
If
CardTypeColumn =
"Virtual"
Then
CType
(dataItem(
"CardTypeImage"
).Controls(0), Image).ImageUrl =
"~/Images/CardVirtual.png"
ElseIf
CardTypeColumn =
"Scratch"
Then
CType
(dataItem(
"CardTypeImage"
).Controls(0), Image).ImageUrl =
"~/Images/CardScratch.png"
ElseIf
CardTypeColumn =
"VirtualOP"
Then
CType
(dataItem(
"CardTypeImage"
).Controls(0), Image).ImageUrl =
"~/Images/CardVirtualOP.png"
ElseIf
CardTypeColumn =
"ScratchOP"
Then
CType
(dataItem(
"CardTypeImage"
).Controls(0), Image).ImageUrl =
"~/Images/CardScratchOP.png"
End
If
Dim
OrderStatusColumn
As
String
= dataItem(
"OrderStatus"
).Text
If
OrderStatusColumn =
"1"
Then
CType
(dataItem(
"OrderStatusImage"
).Controls(0), Image).ImageUrl =
"~/Images/OrderClosed.png"
ElseIf
OrderStatusColumn =
"2"
Then
CType
(dataItem(
"OrderStatusImage"
).Controls(0), Image).ImageUrl =
"~/Images/OrderOpen.png"
ElseIf
OrderStatusColumn =
"3"
Then
CType
(dataItem(
"OrderStatusImage"
).Controls(0), Image).ImageUrl =
"~/Images/OrderSuspended.png"
ElseIf
OrderStatusColumn =
"4"
Then
CType
(dataItem(
"OrderStatusImage"
).Controls(0), Image).ImageUrl =
"~/Images/OrderClosedTr.png"
ElseIf
OrderStatusColumn =
"5"
Then
CType
(dataItem(
"OrderStatusImage"
).Controls(0), Image).ImageUrl =
"~/Images/OrderOpenTr.png"
ElseIf
OrderStatusColumn =
"6"
Then
CType
(dataItem(
"OrderStatusImage"
).Controls(0), Image).ImageUrl =
"~/Images/OrderSuspendedTr.png"
End
If
Dim
HasCreditNoteColumn
As
String
= dataItem(
"HasCreditNote"
).Text
If
HasCreditNoteColumn =
"1"
Then
CType
(dataItem(
"HasCreditNoteImage"
).Controls(0), Image).ImageUrl =
"~/Images/CreditNoteDiscount.png"
ElseIf
HasCreditNoteColumn =
"2"
Then
CType
(dataItem(
"HasCreditNoteImage"
).Controls(0), Image).ImageUrl =
"~/Images/CreditNoteCards.png"
Else
dataItem(
"HasCreditNoteImage"
).Controls(0).Visible =
False
End
If
Dim
TotalChargeColumn
As
String
= dataItem(
"Charge"
).Text
dataItem(
"Charge"
).Text = ConvertStringToDecimal(dataItem(
"Charge"
).Text, 2)
dataItem(
"TotalCharge"
).Text = ConvertStringToDecimal(dataItem(
"TotalCharge"
).Text, 2)
'dataItem("Price").Text = ConvertStringToDecimal(dataItem("Price").Text, 2)
dataItem(
"Charge"
).HorizontalAlign = HorizontalAlign.Right
dataItem(
"TotalCharge"
).HorizontalAlign = HorizontalAlign.Right
'dataItem("Price").HorizontalAlign = HorizontalAlign.Right
dataItem(
"Cards"
).HorizontalAlign = HorizontalAlign.Right
Charge += dataItem(
"TotalCharge"
).Text
Cards += dataItem(
"Cards"
).Text
'If INMBData <> " " Then
' INMBValue += CDec(INMBData)
'End If
'Dim fieldValue As Int32 = Integer.Parse(dataItem("ID").Text)
'TotalCharge = TotalCharge + TotalChargeField
End
If
If
(
TypeOf
e.Item
Is
GridFooterItem)
Then
Dim
footerItem
As
GridFooterItem =
CType
(e.Item, GridFooterItem)
footerItem(
"TotalCharge"
).Text = ConvertStringToDecimal(Charge.ToString, 2)
footerItem(
"TotalCharge"
).HorizontalAlign = HorizontalAlign.Right
footerItem(
"Cards"
).Text = ConvertStringToDecimal(Cards, 0)
footerItem(
"Cards"
).HorizontalAlign = HorizontalAlign.Right
'footerItem("INMB~Data (1.35$ / MIN)").Text = INMBValue.ToString()
footerItem(
"Vessel"
).Controls.Add(
New
LiteralControl(
"<span style='color: Black; font-weight: bold;'>Totals:</span> "
))
End
If
End
Sub