My export to Excel works fine with normal GridBoundColumn columns however will not work with GridTemplateColumn. How might I facilitate a download of the grid? When downloading it only includes Member Type, Phone, Approx Miles. Need it to include CUName, Address, etc.
Thank you for your help
Here is how I populate the fields that are not showing.
Thank you for your help
<
telerik:RadGrid
ID
=
"grdResults"
runat
=
"server"
AllowPaging
=
"true"
AllowSorting
=
"true"
AutoGenerateColumns
=
"False"
CellSpacing
=
"-1"
GridLines
=
"Both"
PageSize
=
"100"
>
<
ExportSettings
IgnorePaging
=
"True"
OpenInNewWindow
=
"True"
ExportOnlyData
=
"True"
FileName
=
"CUMapListings"
>
<
Excel
AutoFitImages
=
"True"
Format
=
"ExcelML"
/>
<
Csv
ColumnDelimiter
=
"VerticalBar"
EncloseDataWithQuotes
=
"False"
/>
</
ExportSettings
>
<
MasterTableView
CommandItemDisplay
=
"Top"
UseAllDataFields
=
"true"
TableLayout
=
"Fixed"
>
<
HeaderStyle
Font-Bold
=
"true"
/>
<
CommandItemTemplate
>
<
asp:LinkButton
ID
=
"btnPrint"
runat
=
"server"
CommandName
=
"PrintResults"
Visible
=
"true"
OnClientClick
=
"PrintRadGrid(); return false;"
><
img
style
=
"border:0px;vertical-align:middle;"
alt
=
""
src
=
"/Images/DownloadPrinter.png"
/>Print</
asp:LinkButton
>
<
asp:LinkButton
ID
=
"btnExportMap"
runat
=
"server"
CommandName
=
"ExportMapListing"
Visible
=
"true"
><
img
style
=
"border:0px;vertical-align:middle;"
alt
=
""
src
=
"/Images/Help/CSV_Export.jpg"
/>Excel Download</
asp:LinkButton
>
</
CommandItemTemplate
>
<
AlternatingItemStyle
BackColor
=
"LightGray"
/>
<
Columns
>
<
telerik:GridTemplateColumn
UniqueName
=
"RowNumber"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lblRowNumber"
runat
=
"server"
/>
</
ItemTemplate
>
<
ItemStyle
Font-Bold
=
"true"
/>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"_search_asiNum"
Visible
=
"false"
DataField
=
"asi_num"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"_search_asiNum"
runat
=
"server"
/>
</
ItemTemplate
>
<
ItemStyle
Font-Bold
=
"true"
/>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"CUInfo"
HeaderText
=
"ADDRESS"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lblCULink"
runat
=
"server"
Visible
=
"false"
/>
<
asp:LinkButton
runat
=
"server"
ID
=
"CU_LinkButton"
Visible
=
"false"
></
asp:LinkButton
>
<
br
/>
<
asp:Label
ID
=
"lblAddressInfo"
runat
=
"server"
Visible
=
"True"
/>
</
ItemTemplate
>
<
HeaderStyle
HorizontalAlign
=
"Center"
/>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"MEMBER"
UniqueName
=
"MemberType"
FilterControlAltText
=
"Filter column column"
DataField
=
"MemberType"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ItemStyle
HorizontalAlign
=
"Center"
/>
<
HeaderStyle
HorizontalAlign
=
"Center"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"PHONE"
UniqueName
=
"Phone"
FilterControlAltText
=
"Filter column column"
DataField
=
"cuPhone"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ItemStyle
HorizontalAlign
=
"Center"
/>
<
HeaderStyle
HorizontalAlign
=
"Center"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"APPROX. MILES"
UniqueName
=
"Miles"
FilterControlAltText
=
"Filter column column"
DataField
=
"Distance"
DataFormatString
=
"{0:####.#0}"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ItemStyle
HorizontalAlign
=
"Center"
/>
<
HeaderStyle
HorizontalAlign
=
"Center"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"Directions"
HeaderText
=
"DRIVING DIRECTION"
>
<
ItemTemplate
>
<
asp:PlaceHolder
runat
=
"server"
>
<
a
href
=
"http://google.com/maps/dir/<;%# DataBinder.Eval(Container.DataItem, "
Address1")%>%2C+<%# DataBinder.Eval(Container.DataItem, "City")%>+<%# DataBinder.Eval(Container.DataItem, "state_id")%>+<%# DataBinder.Eval(Container.DataItem, "zip_code")%>/<%# Request.QueryString("A")%>%2C+<%# Request.QueryString("C")%>+<%# Request.QueryString("S")%>+<%# Request.QueryString("Z")%>" target="_blank">To <%# Request.QueryString("N")%></
a
>
<
br
/>
<
a
href
=
"http://google.com/maps/dir/<;%# Request.QueryString("
A")%>%2C+<%# Request.QueryString("C")%>+<%# Request.QueryString("S")%>+<%# Request.QueryString("Z")%>/<%# DataBinder.Eval(Container.DataItem, "Address1")%>%2C+<%# DataBinder.Eval(Container.DataItem, "City")%>+<%# DataBinder.Eval(Container.DataItem, "state_id")%>+<%# DataBinder.Eval(Container.DataItem, "zip_code")%>" target="_blank">From <%# Request.QueryString("N")%></
a
>
</
asp:PlaceHolder
>
</
ItemTemplate
>
<
HeaderStyle
HorizontalAlign
=
"Center"
/>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
<
PagerStyle
PageSizeControlType
=
"RadComboBox"
/>
</
telerik:RadGrid
>
Here is how I populate the fields that are not showing.
Private
Sub
grdResults_ItemCommand(sender
As
Object
, e
As
GridCommandEventArgs)
Handles
grdResults.ItemCommand
If
e.CommandName =
"ExportMapListing"
Then
grdResults.ExportSettings.ExportOnlyData =
True
grdResults.ExportSettings.FileName =
"ExportMapListing"
grdResults.MasterTableView.ExportToExcel()
End
If
End
Sub
Private
Sub
grdResults_ItemDataBound(sender
As
Object
, e
As
Telerik.Web.UI.GridItemEventArgs)
Handles
grdResults.ItemDataBound
'Set Row Count
If
TypeOf
e.Item
Is
Telerik.Web.UI.GridDataItem
Then
Dim
rowCounter
As
Integer
= 0
Dim
lblRowNumber
As
Label = TryCast(e.Item.FindControl(
"lblRowNumber"
), Label)
rowCounter = grdResults.MasterTableView.PageSize * grdResults.MasterTableView.CurrentPageIndex
lblRowNumber.Text = (e.Item.ItemIndex + 1 + rowCounter).ToString()
Dim
lblCULink
As
Label = TryCast(e.Item.FindControl(
"lblCULink"
), Label)
Dim
CU_LinkButton
As
LinkButton = TryCast(e.Item.FindControl(
"CU_LinkButton"
), LinkButton)
Dim
lblAddressInfo
As
Label = TryCast(e.Item.FindControl(
"lblAddressInfo"
), Label)
lblAddressInfo.Text = DataBinder.Eval(e.Item.DataItem,
"Address1"
) &
"<br />"
& _
DataBinder.Eval(e.Item.DataItem,
"City"
) &
" "
& _
DataBinder.Eval(e.Item.DataItem,
"state_id"
) &
" "
& _
DataBinder.Eval(e.Item.DataItem,
"zip_code"
)
If
DataBinder.Eval(e.Item.DataItem,
"MemberType"
) =
"Non-member"
Then
e.Item.ForeColor = Drawing.Color.Black
lblCULink.Visible =
True
lblCULink.Text =
"<a href="
"/cuDataAnalysis/cuSummary.aspx?Charter_num="
& DataBinder.Eval(e.Item.DataItem,
"charter_num"
) &
""
">"
& DataBinder.Eval(e.Item.DataItem,
"CUName"
) &
" ("
& DataBinder.Eval(e.Item.DataItem,
"charter_num"
) &
")</a>"
CU_LinkButton.Visible =
False
Else
e.Item.ForeColor = Drawing.Color.Green
'lblCULink.Text = "<a href=""/CUTracking/ContactManager/default.aspx?_search_asiNum=" & DataBinder.Eval(e.Item.DataItem, "asi_num") & """>" & DataBinder.Eval(e.Item.DataItem, "CUName") & " (" & DataBinder.Eval(e.Item.DataItem, "charter_num") & ")</a>"
lblCULink.Visible =
False
CU_LinkButton.Visible =
True
CU_LinkButton.PostBackUrl =
"/CUTracking/ContactManager/default.aspx"
'?_search_asiNum=" & DataBinder.Eval(e.Item.DataItem, "asi_num")
CU_LinkButton.Text = DataBinder.Eval(e.Item.DataItem,
"CUName"
) &
" ("
& DataBinder.Eval(e.Item.DataItem,
"charter_num"
) &
")"
End
If
End
If
End
Sub