Hi all!!!
I have a grid with several columns. When I try to export to csv, all the columns are exported correctly, except for the one that is defined as GripDropdwonColumn. Do you know where the problem can be?
I attach the code regarding grid definition and C# code for grid events:
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
BackgroundPosition
=
"Center"
>
</
telerik:RadAjaxLoadingPanel
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowMultiRowSelection
=
"True"
ShowStatusBar
=
"True"
AllowFilteringByColumn
=
"True"
AllowSorting
=
"True"
EnableHeaderContextMenu
=
"true"
AllowPaging
=
"True"
GridLines
=
"None"
Width
=
"99.8%"
AutoGenerateColumns
=
"False"
CellPadding
=
"0"
CellSpacing
=
"0"
PagerStyle-AlwaysVisible
=
"true"
HeaderStyle-ForeColor
=
"Black"
HeaderStyle-Font-Bold
=
"true"
OnUpdateCommand
=
"RadGridUrl_UpdateCommand"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
OnItemCreated
=
"RadGrid1_ItemCreated"
OnItemCommand
=
"RadGrid1_ItemCommand"
>
<
GroupingSettings
CaseSensitive
=
"false"
/>
<
MasterTableView
TableLayout
=
"Fixed"
ClientDataKeyNames
=
"VeM_InvoiceId"
Font-Size
=
"11px"
CommandItemDisplay
=
"Bottom"
InsertItemPageIndexAction
=
"ShowItemOnCurrentPage"
>
<
CommandItemSettings
ShowAddNewRecordButton
=
"false"
ShowRefreshButton
=
"false"
ShowExportToExcelButton
=
"true"
ShowExportToCsvButton
=
"true"
></
CommandItemSettings
>
<
Columns
>
<
telerik:GridEditCommandColumn
HeaderStyle-Width
=
"20px"
ButtonType
=
"ImageButton"
UniqueName
=
"GridButtonColumnEdit"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"Center"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Invoice"
DataField
=
"VeM_InvoiceId"
UniqueName
=
"VeM_InvoiceId"
FilterControlWidth
=
"45%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
ReadOnly
=
"True"
HeaderStyle-Width
=
"60px"
Visible
=
"false"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Invoice Number"
DataField
=
"InvoiceNumber"
UniqueName
=
"InvoiceNumber"
FilterControlWidth
=
"60%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
HeaderStyle-Width
=
"130px"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Invoicing VeOffice"
DataField
=
"TerritoryName"
UniqueName
=
"TerritoryName"
FilterControlWidth
=
"60%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
ReadOnly
=
"True"
/>
<
telerik:GridBoundColumn
HeaderText
=
"License"
DataField
=
"LicenseName"
UniqueName
=
"LicenseName"
FilterControlWidth
=
"60%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
ReadOnly
=
"True"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Customer"
DataField
=
"CustomerName"
UniqueName
=
"CustomerName"
FilterControlWidth
=
"60%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
ReadOnly
=
"True"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Country"
DataField
=
"Country"
UniqueName
=
"Country"
FilterControlWidth
=
"60%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
ReadOnly
=
"True"
/>
<
telerik:GridDropDownColumn
UniqueName
=
"InvoiceStatus"
ListTextField
=
"Name"
ListValueField
=
"VeM_InvoiceStatusId"
DataField
=
"VeM_InvoiceStatusId"
HeaderText
=
"Status"
DropDownControlType
=
"RadComboBox"
FilterControlWidth
=
"60%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
HeaderStyle-Width
=
"75px"
/>
<
telerik:GridBoundColumn
DataField
=
"VeM_InvoiceStatusName"
HeaderText
=
"InvoiceStatusName"
SortExpression
=
"VeM_InvoiceStatusName"
UniqueName
=
"VeM_InvoiceStatusName"
Display
=
"false"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Invoiced Date"
DataField
=
"DateCreated"
UniqueName
=
"DateCreated"
FilterControlWidth
=
"60%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
ReadOnly
=
"True"
/>
<
telerik:GridDateTimeColumn
HeaderText
=
"Payment Date"
DataField
=
"DatePaid"
UniqueName
=
"DatePaid"
FilterControlWidth
=
"100%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
PickerType
=
"DatePicker"
/>
<
telerik:GridBoundColumn
HeaderText
=
""
DataField
=
"Symbol"
UniqueName
=
"Symbol"
AllowFiltering
=
"false"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
ReadOnly
=
"True"
HeaderStyle-Width
=
"20px"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Invoice Total"
DataField
=
"InvoiceTotal"
UniqueName
=
"InvoiceTotal"
FilterControlWidth
=
"60%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
DataFormatString
=
"{0:#,0.00}"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Number Sales"
DataField
=
"NumberSales"
UniqueName
=
"NumberSales"
FilterControlWidth
=
"60%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Total Sales"
DataField
=
"TotalSales"
UniqueName
=
"TotalSales"
FilterControlWidth
=
"60%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
DataFormatString
=
"{0:#,0.00}"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Number Cancellations"
DataField
=
"NumberCancelations"
UniqueName
=
"NumberCancelations"
FilterControlWidth
=
"60%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Total Cancellations"
DataField
=
"TotalCancelations"
UniqueName
=
"TotalCancelations"
FilterControlWidth
=
"60%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
DataFormatString
=
"{0:#,0.00}"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Updated Date"
DataField
=
"DateUpdated"
UniqueName
=
"DateUpdated"
FilterControlWidth
=
"60%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
ReadOnly
=
"True"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Comments"
DataField
=
"Comments"
UniqueName
=
"Comments"
FilterControlWidth
=
"60%"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"true"
CurrentFilterFunction
=
"Contains"
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"center"
Visible
=
"false"
/>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
EnableRowHoverStyle
=
"true"
/>
<
PagerStyle
Mode
=
"NextPrevNumericAndAdvanced"
PagerTextFormat
=
"{4} Records {2} to {3} of {5}"
></
PagerStyle
>
<
ExportSettings
ExportOnlyData
=
"false"
></
ExportSettings
>
</
telerik:RadGrid
>
<
telerik:RadFormDecorator
ID
=
"FormDecoratorMaster"
runat
=
"server"
DecoratedControls
=
"all"
>
</
telerik:RadFormDecorator
>
<
telerik:RadToolTipManager
ID
=
"RadToolTipManager1"
runat
=
"server"
RelativeTo
=
"Element"
AutoTooltipify
=
"true"
ContentScrolling
=
"Default"
EnableAriaSupport
=
"true"
EnableShadow
=
"true"
Position
=
"TopCenter"
Animation
=
"FlyIn"
>
</
telerik:RadToolTipManager
>
protected
void
RadGridUrl_UpdateCommand(
object
source, GridCommandEventArgs e)
{
bool
process =
true
;
IControlPanelPersistenceProvider persistenceProvider =
new
ControlPanelDatabaseProvider();
m_resultMessage.Visible =
false
;
var editableItem = ((GridEditableItem)e.Item);
VeM_Invoice invoice =
new
VeM_Invoice();
invoice.VeM_InvoiceId = (
int
)editableItem.GetDataKeyValue(
"VeM_InvoiceId"
);
//populate its properties
Hashtable values =
new
Hashtable();
editableItem.ExtractValues(values);
int
invoiceStatusId = 0;
int
.TryParse((editableItem[
"InvoiceStatus"
].Controls[0]
as
RadComboBox).SelectedValue,
out
invoiceStatusId);
invoice.VeM_InvoiceStatusId = invoiceStatusId;
if
(values[
"DatePaid"
] !=
null
)
{
invoice.DatePaid = DateTime.Parse((
string
)values[
"DatePaid"
]);
}
if
(values[
"InvoiceTotal"
] !=
null
)
{
try
{
invoice.InvoiceTotal =
double
.Parse((
string
)values[
"InvoiceTotal"
]);
}
catch
{
process =
false
;
m_resultMessage.Text =
"Invoice Total is a numeric value"
;
m_resultMessage.Visible =
true
;
}
}
else
{
process =
false
;
m_resultMessage.Text =
"Invoice Total is required"
;
m_resultMessage.Visible =
true
;
}
if
(values[
"NumberSales"
] !=
null
)
{
try
{
invoice.NumberSales =
int
.Parse((
string
)values[
"NumberSales"
]);
}
catch
{
process =
false
;
m_resultMessage.Text =
"Number Sales is a numeric value"
;
m_resultMessage.Visible =
true
;
}
}
else
{
process =
false
;
m_resultMessage.Text =
"Number Sales is required"
;
m_resultMessage.Visible =
true
;
}
if
(values[
"TotalSales"
] !=
null
)
{
try
{
invoice.TotalSales =
double
.Parse((
string
)values[
"TotalSales"
]);
}
catch
{
process =
false
;
m_resultMessage.Text =
"Total Sales is a numeric value"
;
m_resultMessage.Visible =
true
;
}
}
else
{
process =
false
;
m_resultMessage.Text =
"Total Sales is required"
;
m_resultMessage.Visible =
true
;
}
if
(values[
"NumberCancelations"
] !=
null
)
{
try
{
invoice.NumberCancelations =
int
.Parse((
string
)values[
"NumberCancelations"
]);
}
catch
{
process =
false
;
m_resultMessage.Text =
"Number Cancelations is a numeric value"
;
m_resultMessage.Visible =
true
;
}
}
else
{
process =
false
;
m_resultMessage.Text =
"Number Cancelations is required"
;
m_resultMessage.Visible =
true
;
}
if
(values[
"TotalCancelations"
] !=
null
)
{
try
{
invoice.TotalCancelations =
double
.Parse((
string
)values[
"TotalCancelations"
]);
}
catch
{
process =
false
;
m_resultMessage.Text =
"Total Cancelations is a numeric value"
;
m_resultMessage.Visible =
true
;
}
}
else
{
process =
false
;
m_resultMessage.Text =
"Total Cancelations is required"
;
m_resultMessage.Visible =
true
;
}
//Comments
if
(values[
"Comments"
] !=
null
)
{
invoice.Comments = (
string
)values[
"Comments"
];
}
//InvoiceNumberEdited
if
(values[
"InvoiceNumber"
] !=
null
)
{
invoice.InvoiceNumberEdited = (
string
)values[
"InvoiceNumber"
];
}
else
{
process =
false
;
m_resultMessage.Text =
"InvoiceNumber is required"
;
m_resultMessage.Visible =
true
;
}
invoice.DateUpdated = DateTime.Now;
if
(process)
{
DataBaseEnum dataBaseEnum = persistenceProvider.SaveInvoice(invoice);
switch
(dataBaseEnum)
{
case
DataBaseEnum.UpdateOK:
m_resultMessage.Text =
"Invoice Saved"
;
m_resultMessage.Visible =
true
;
PopulateGrid(
true
);
break
;
case
DataBaseEnum.UpdateError:
m_resultMessage.Text =
"Error saving the invoice"
;
m_resultMessage.Visible =
true
;
break
;
}
}
}
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem && !e.Item.IsInEditMode)
{
GridDataItem item = (GridDataItem)e.Item;
Literal invoiceStatus = (Literal)item[
"InvoiceStatus"
].Controls[0];
invoiceStatus.Text = (
string
)DataBinder.Eval(item.DataItem,
"VeM_InvoiceStatusName"
);
}
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
//first reference the edited grid item
GridEditableItem editedItem = e.Item
as
GridEditableItem;
GridEditManager editMan = editedItem.EditManager;
GridTextBoxColumnEditor nameDisplayField = editMan.GetColumnEditor(
"Comments"
)
as
GridTextBoxColumnEditor;
nameDisplayField.TextBoxControl.TextMode = TextBoxMode.MultiLine;
IControlPanelPersistenceProvider persistenceProvider =
new
ControlPanelDatabaseProvider();
List<VeM_InvoiceStatus> invoiceStatusCollection = persistenceProvider.ListInvoiceStatus();
GridDropDownColumnEditor invoiceStatusDropdown = editMan.GetColumnEditor(
"InvoiceStatus"
)
as
GridDropDownColumnEditor;
invoiceStatusDropdown.DataSource = invoiceStatusCollection;
invoiceStatusDropdown.DataBind();
invoiceStatusDropdown.SelectedValue = ((Ve.Apps.ConfigurationUI.BusinessObjects.Invoice)editedItem.DataItem).VeM_InvoiceStatusId.ToString();
}
if
(e.Item
is
GridFilteringItem)
{
GridFilteringItem item = e.Item
as
GridFilteringItem;
((item[
"InvoiceStatus"
].Controls[0])
as
TextBox).Text = ((item[
"VeM_InvoiceStatusName"
].Controls[0])
as
TextBox).Text;
}
}
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
Country country = (Country)Session[
"cultureInfo"
];
string
locale = country.Language;
if
(locale !=
"en"
)
{
TranslationHandler myHandler =
new
TranslationHandler(locale, Server.MapPath(
""
));
if
(e.Item
is
GridPagerItem)
{
Button GoToPageLinkButton = (Button)e.Item.FindControl(
"GoToPageLinkButton"
);
GoToPageLinkButton.Text = myHandler.GetString(
"VeM_Grid_Go"
);
Button ChangePageSizeLinkButton = (Button)e.Item.FindControl(
"ChangePageSizeLinkButton"
);
ChangePageSizeLinkButton.Text = myHandler.GetString(
"VeM_Grid_Change"
);
Label changePageLabel = (Label)e.Item.FindControl(
"GoToPageLabel"
);
changePageLabel.Text = myHandler.GetString(
"VeM_Grid_Page"
);
Label lblPageSize = (Label)e.Item.FindControl(
"ChangePageSizeLabel"
);
lblPageSize.Text = myHandler.GetString(
"VeM_Grid_PageSize"
);
Label lblPageOf = (Label)e.Item.FindControl(
"PageOfLabel"
);
lblPageOf.Text = myHandler.GetString(
"VeM_Grid_Of"
);
RadGrid1.PagerStyle.PagerTextFormat =
"{4} "
+ myHandler.GetString(
"VeM_Grid_Records"
) +
" {2} "
+ myHandler.GetString(
"VeM_Grid_To"
) +
" {3} "
+ myHandler.GetString(
"VeM_Grid_Of"
) +
" {5}"
;
}
}
}
protected
void
RadGrid1_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.FilterCommandName)
{
Pair command = (Pair)e.CommandArgument;
if
(command.Second.ToString() ==
"InvoiceStatus"
)
{
e.Canceled =
true
;
GridFilteringItem filter = (GridFilteringItem)e.Item;
((filter[
"VeM_InvoiceStatusName"
].Controls[0])
as
TextBox).Text = ((filter[
"InvoiceStatus"
].Controls[0])
as
TextBox).Text;
command.Second =
"VeM_InvoiceStatusName"
;
filter.FireCommandEvent(
"Filter"
,
new
Pair(command.First,
"VeM_InvoiceStatusName"
));
}
}
}