<telerik:RadGrid ID="rgContacts" runat="server" AutoGenerateColumns="False" OnNeedDataSource="rgContacts_NeedDataSource" Skin="Silk" ShowHeader="false" GridLines="None" BorderStyle="Groove" BorderWidth="1px" Width="250px" BorderColor="#555555" AlternatingItemStyle-BackColor="White" BackColor="#bbeaf3"> <MasterTableView DataKeyNames="contact_id" EditMode="PopUp"> <CommandItemSettings ShowRefreshButton="false" AddNewRecordText="Add a New Contact"/> <EditFormSettings PopUpSettings-Modal="true" UserControlName="controls/Contacts/CustomerContact.ascx" EditFormType="WebUserControl" InsertCaption="Create New Contact" CaptionFormatString="Edit Contact" FormCaptionStyle-Font-Bold="true" FormCaptionStyle-Font-Size="X-Large" FormStyle-BackColor="#dedddc" />Hi,
My requirement is to export RadGrid data to excel when user clicks on button outside RadGrid.
The following are the customizations that are needed:
1) Save or Open dialogue box should show up for opening or saving excel file.
2) Add company logo to excel file at certain position. Like row1 column1 to row5 column5. Logo size (gif format) is
always going to be same. Currently we are doing it by accessing worksheet and adding it.
3) we should be able to specify from where data should start showing up like row7..
4) We are hiding some columns in the grid. When exported, these shouldn't be exported.
5) Some rows in the grid are disabled. User can't click them. They shouldn't be exported.
6) Add a title and format it.
7) Format print options like margin etc..
I appreciate your help. Please let me know if there are any links about how to take care of it.
Thanks,
Prathiba.
radGuage.Pointer.Value =
Convert.ToDecimal(7.5);
<
telerik:RadRadialGauge ID="radGuage" runat="server" Skin="WebBlue">
<Pointer Color="Green">
<Cap Color="Lime" />
</Pointer>
<Scale MajorUnit="1" Max="8" Min="1" MinorUnit=".5">
<Labels Color="Black" Position="Outside" Visible="False" />
<Ranges>
<telerik:GaugeRange Color="#ccffcc" From="1" To="2" />
<telerik:GaugeRange Color="#99ccff" From="2" To="3" />
<telerik:GaugeRange Color="#0067b4" From="3" To="4" />
<telerik:GaugeRange Color="#826eb1" From="4" To="5" />
<telerik:GaugeRange Color="#ffff99" From="5" To="6" />
<telerik:GaugeRange Color="#ff9900" From="6" To="7" />
<telerik:GaugeRange Color="#ff6666" From="7" To="8" />
</Ranges>
</Scale>
</telerik:RadRadialGauge>
<telerik:GridButtonColumn ConfirmText="¿Eliminar registro?" ConfirmDialogType="RadWindow" ConfirmTitle="Eliminar" ButtonType="ImageButton" CommandName="Delete" ConfirmDialogHeight="140px" ConfirmDialogWidth="250px" ItemStyle-HorizontalAlign="Center" /><table cellpadding="0" cellspacing="0" border="0" width="990"> <tr> <td class="legendcolor" style="width: 450; text-align: center"> Activity Codes </td> <td class="legendcolor" style="width: 450; text-align: center"> Pay Groups </td> </tr> <tr> <td valign="top" style="width: 450; text-align: center"> <telerik:RadFilter Width="450" runat="server" ID="RadFilter2" Visible="false" FilterContainerID="RadGridActivity" EnableEmbeddedSkins="true" ShowApplyButton="false" /> <telerik:RadGrid ID="RadGridActivity" runat="server" OnItemCommand="RadGridActivity_ItemCommand" OnItemDataBound="RadGridActivity_ItemDataBound" OnItemCreated="RadGridActivity_ItemCreated" OnUpdateCommand="RadGridActivity_UpdateCommand" AutoGenerateColumns="False" PageSize="15" AllowPaging="True" AllowSorting="True" OnExcelExportCellFormatting="RadGridActivity_ExcelExportCellFormatting" OnInsertCommand="RadGridActivity_InsertCommand" CellSpacing="0" DataSourceID="ldsActivityCodes" GridLines="None" AllowFilteringByColumn="true" OnCSVExportCellFormatting="RadGridActivity_CSVExportCellFormatting" OnDeleteCommand="RadGridActivity_DeleteCommand"> <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"> </HeaderContextMenu> <MasterTableView DataKeyNames="ID" DataSourceID="ldsActivityCodes" TableLayout="Fixed" IsFilterItemExpanded="false" CommandItemDisplay="Top" OverrideDataSourceControlSorting="true"> <CommandItemTemplate> <telerik:RadToolBar runat="server" ID="RadToolBar2" Height="24px" EnableEmbeddedSkins="true" OnButtonClick="RadToolBar2_ButtonClick" EnableRoundedCorners="true"> <Items> <telerik:RadToolBarButton Text="Show filter" CommandName="OpenRadFilter" /> <telerik:RadToolBarButton Text="Apply filter" CommandName="FilterRadGrid" /> <telerik:RadToolBarButton Text="Clear Filter" CommandName="ClearFilter" /> <telerik:RadToolBarButton Text="Hide filter" CommandName="CloseRadFilter" /> <telerik:RadToolBarButton Width="40px" Text="" CommandName="" /> <telerik:RadToolBarButton Text="" CommandName=""> <ItemTemplate> <telerik:RadButton ID="ExcelExportButton2" runat="server" Image-EnableImageButton="true" Image-ImageUrl="images/Export2Excel.gif" ToolTip="Export to Excel this page. Click Yes at MS 'different format' error message." Width="44px" Height="22px" CommandName="ExportToExcel" /> <telerik:RadButton ID="RadButton2" runat="server" Width="1px" Height="1px" /> <telerik:RadButton ID="CSVExportButton2" runat="server" Image-EnableImageButton="true" Image-ImageUrl="images/Export2CSV.gif" ToolTip="Export to CSV this page" Width="44px" Height="22px" CommandName="ExportToCSV" /> <telerik:RadButton ID="RadButton5" runat="server" Width="1px" Height="1px" /> <telerik:RadButton ID="AddButton" runat="server" Image-EnableImageButton="true" Image-ImageUrl="images/2Add.gif" ToolTip="Add New Employee" Width="44px" Height="22px" CommandName="InitInsert" /> </ItemTemplate> </telerik:RadToolBarButton> </Items> </telerik:RadToolBar> </CommandItemTemplate> <Columns> <telerik:GridBoundColumn DataField="FullName" FilterControlAltText="Filter FullName column" HeaderText="FullName" Visible="false" SortExpression="FullName" AllowFiltering="false" UniqueName="FullName"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" FilterControlAltText="Filter ID column" HeaderText="ID" Visible="false" SortExpression="ID" AllowFiltering="false" UniqueName="ID"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Code" DataType="System.Int32" FilterControlAltText="Filter Code column" HeaderText="Activity Code" ReadOnly="true" SortExpression="Code" UniqueName="Code"> <HeaderStyle HorizontalAlign="Center" VerticalAlign="Top" Wrap="False" /> <ItemStyle HorizontalAlign="Center" Wrap="False" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Description" FilterControlAltText="Filter Description column" HeaderText="Description" ReadOnly="true" SortExpression="Description" UniqueName="Description"> <HeaderStyle HorizontalAlign="Center" Width="200" VerticalAlign="Top" Wrap="False" /> <ItemStyle HorizontalAlign="Center" Width="200" Wrap="False" /> </telerik:GridBoundColumn> <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" HeaderText="Edit" ButtonType="ImageButton" /> <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" HeaderText="Delete" CommandName="Delete" ButtonType="ImageButton" /> </Columns> <EditFormSettings EditFormType="Template"> <FormTemplate> <table> <tr> <td class="gtempname"> Activity Code #: </td> <td align="left"> <telerik:RadNumericTextBox ID="txtActivityCode" runat="server" Width="30px" CssClass="gtextbox" Type="Number" NumberFormat-DecimalDigits="0" DbValue='<%# Bind("Code") %>' /> </td> </tr> <tr> <td class="gtempname"> Description: </td> <td align="left"> <asp:TextBox Width="150px" ID="txtACDescription" runat="server" CssClass="gtextbox" Text='<%# Bind("Description") %>'></asp:TextBox> </td> </tr> <tr> <td colspan="2"> <center> <asp:Button ID="btnUpdate" runat="server" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'> </asp:Button> <asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" CommandName="Cancel"></asp:Button></center> </td> </tr> </table> </FormTemplate> <EditColumn FilterControlAltText="Filter EditCommandColumn column"> </EditColumn> </EditFormSettings> </MasterTableView> <FilterMenu EnableImageSprites="False"> </FilterMenu> </telerik:RadGrid> </td> <td valign="top" style="width: 450; text-align: center"> <telerik:RadFilter Width="450" runat="server" ID="RadFilter3" Visible="false" FilterContainerID="RadGridPayGroups" EnableEmbeddedSkins="true" ShowApplyButton="false" /> <telerik:RadGrid ID="RadGridPayGroups" runat="server" OnExcelExportCellFormatting="RadGridPayGroups_ExcelExportCellFormatting" OnItemCreated="RadGridPayGroups_ItemCreated" OnDeleteCommand="RadGridPayGroups_DeleteCommand" AutoGenerateColumns="False" PageSize="15" AllowPaging="True" AllowSorting="True" OnItemCommand="RadGridPayGroups_ItemCommand" OnItemDataBound="RadGridPayGroups_ItemDataBound" OnUpdateCommand="RadGridPayGroups_UpdateCommand" CellSpacing="0" DataSourceID="ldsPayGroups" GridLines="None" AllowFilteringByColumn="true" OnCSVExportCellFormatting="RadGridPayGroups_CSVExportCellFormatting" OnInsertCommand="RadGridPayGroups_InsertCommand"> <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"> </HeaderContextMenu> <MasterTableView DataKeyNames="ID" DataSourceID="ldsPayGroups" TableLayout="Fixed" IsFilterItemExpanded="false" CommandItemDisplay="Top" OverrideDataSourceControlSorting="true"> <CommandItemSettings ExportToPdfText="Export to PDF" /> <CommandItemTemplate> <telerik:RadToolBar runat="server" ID="RadToolBar3" Height="24px" EnableEmbeddedSkins="true" OnButtonClick="RadToolBar3_ButtonClick" EnableRoundedCorners="true"> <Items> <telerik:RadToolBarButton Text="Show filter" CommandName="OpenRadFilter" /> <telerik:RadToolBarButton Text="Apply filter" CommandName="FilterRadGrid" /> <telerik:RadToolBarButton Text="Clear Filter" CommandName="ClearFilter" /> <telerik:RadToolBarButton Text="Hide filter" CommandName="CloseRadFilter" /> <telerik:RadToolBarButton Width="40px" Text="" CommandName="" /> <telerik:RadToolBarButton Text="" CommandName=""> <ItemTemplate> <telerik:RadButton ID="ExcelExportButton3" runat="server" Image-EnableImageButton="true" Image-ImageUrl="images/Export2Excel.gif" ToolTip="Export to Excel this page. Click Yes at MS 'different format' error message." Width="44px" Height="22px" CommandName="ExportToExcel" /> <telerik:RadButton ID="RadButton3" runat="server" Width="1px" Height="1px" /> <telerik:RadButton ID="CSVExportButton3" runat="server" Image-EnableImageButton="true" Image-ImageUrl="images/Export2CSV.gif" ToolTip="Export to CSV this page" Width="44px" Height="22px" CommandName="ExportToCSV" /> <telerik:RadButton ID="RadButton4" runat="server" Width="1px" Height="1px" /> <telerik:RadButton ID="AddButton" runat="server" Image-EnableImageButton="true" Image-ImageUrl="images/2Add.gif" ToolTip="Add New Employee" Width="44px" Height="22px" CommandName="InitInsert" /> </ItemTemplate> </telerik:RadToolBarButton> </Items> </telerik:RadToolBar> </CommandItemTemplate> <Columns> <telerik:GridBoundColumn DataField="FullName" FilterControlAltText="Filter FullName column" FilterControlWidth="1" HeaderText="FullName" Visible="false" AllowFiltering="false" SortExpression="FullName" UniqueName="FullName"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" FilterControlAltText="Filter ID column" FilterControlWidth="1" HeaderText="ID" Visible="false" AllowFiltering="false" SortExpression="ID" UniqueName="ID"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="PayGroupCode" DataType="System.Int32" FilterControlAltText="Filter PayGroupCode column" HeaderText="PayGroupCode" ReadOnly="True" SortExpression="PayGroupCode" UniqueName="PayGroupCode" FilterControlWidth="100"> <HeaderStyle HorizontalAlign="Center" VerticalAlign="Top" Wrap="False" /> <ItemStyle HorizontalAlign="Center" Wrap="False" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Description" FilterControlAltText="Filter Description column" FilterControlWidth="200" HeaderText="Description" ReadOnly="true" SortExpression="Description" UniqueName="Description"> <HeaderStyle HorizontalAlign="Center" Width="200" VerticalAlign="Top" Wrap="False" /> <ItemStyle HorizontalAlign="Center" Width="200" Wrap="False" /> </telerik:GridBoundColumn> <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" HeaderText="Edit" ButtonType="ImageButton" FilterControlWidth="75" /> <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" HeaderText="Delete" CommandName="Delete" ButtonType="ImageButton" FilterControlWidth="75" /> </Columns> <EditFormSettings EditFormType="Template"> <FormTemplate> <table> <tr> <td class="gtempname"> PayGroupCode #: </td> <td align="left"> <telerik:RadNumericTextBox ID="txtPayGroupCode" runat="server" Width="30px" CssClass="gtextbox" Type="Number" NumberFormat-DecimalDigits="0" DbValue='<%# Bind("PayGroupCode") %>' /> </td> </tr> <tr> <td class="gtempname"> Description: </td> <td align="left"> <asp:TextBox Width="150px" ID="txtPGDescription" runat="server" CssClass="gtextbox" Text='<%# Bind("Description") %>'></asp:TextBox> </td> </tr> <tr> <td colspan="2"> <center> <asp:Button ID="btnUpdate" runat="server" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'> </asp:Button> <asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" CommandName="Cancel"></asp:Button></center> </td> </tr> </table> </FormTemplate> <EditColumn FilterControlAltText="Filter EditCommandColumn column"> </EditColumn> </EditFormSettings> </MasterTableView> <FilterMenu EnableImageSprites="False"> </FilterMenu> </telerik:RadGrid> </td> </tr> </table><br /> <telerik:RadGrid ID="rgPhysicalAccessReviewList" runat="server" ShowStatusBar="true" Visible="false" OnInit="rgPhysicalAccessReviewList_Init"
AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="False" AllowMultiRowEdit="true" AllowFilteringByColumn="true"
OnItemCommand="rgPhysicalAccessReviewList_ItemCommand" OnItemDataBound="rgPhysicalAccessReviewList_ItemDataBound" EnableViewState="true"
AllowPaging="true" PageSize="150" OnNeedDataSource="rgPhysicalAccessReviewList_NeedDataSource">
<PagerStyle Mode="NumericPages"></PagerStyle>
<MasterTableView Width="100%" DataKeyNames="EmployeeID, AccessReviewID" EnableColumnsViewState="true" AllowMultiColumnSorting="True" HeaderStyle-Font-Bold="true" EditMode="EditForms">
<NoRecordsTemplate>
<div>No records to display</div>
</NoRecordsTemplate>
<Columns>
<telerik:GridTemplateColumn AllowFiltering="false" HeaderStyle-HorizontalAlign="Left" HeaderText="Business Manager Comments" HeaderStyle-Width ="300px" HeaderButtonType="TextButton" UniqueName="CommentsBox">
<ItemTemplate>
<asp:TextBox ID="txtBxComments" OnTextChanged="txtBxComments_OnTextChanged" Text='<%# Eval("ManagerComments") %>' AutoPostBack="true" runat="server" TextMode="MultiLine" Wrap="True" MaxLength="500" Height="50px" Width="300px"></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn AllowFiltering="false" HeaderStyle-HorizontalAlign="Left" HeaderText="Previous Quarter Comments" HeaderStyle-Width ="300px" HeaderButtonType="TextButton" UniqueName="PQCommentsBox">
<ItemTemplate>
<asp:Label ID="lblComments" runat="server"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<NestedViewTemplate>
<telerik:RadGrid ID="rgEmployeeDetails" AutoGenerateColumns="False" runat="server" AllowPaging="True" BorderWidth="0px" OnNeedDataSource="rgEmployeeDetails_NeedDataSource">
<MasterTableView Width="75%" DataKeyNames="EmployeeID" ShowHeader="false" AllowMultiColumnSorting="True" >
<Columns>
<telerik:GridTemplateColumn HeaderStyle-BorderWidth="0px">
<ItemTemplate>
<asp:Panel ID="NestedViewPanel" runat="server" CssClass="viewWrap">
<div class="contactWrap">
<fieldset style="padding: 10px;">
<legend style="padding: 5px;"><b>Details of Employee: <%#Eval("LastName")%>, <%#Eval("FirstName")%></b>
</legend>
<table>
<tbody>
<tr>
<td>
<table class="fontDetails">
<tbody>
<tr>
<td style="font-weight: bold;">
Access Coordinator:
</td>
<td>
<asp:Label ID="Label2" Text='<%#Bind("AccessCoordinator") %>' runat="server"></asp:Label>
</td>
<td style="font-weight: bold;">
AC Phone:
</td>
<td>
<asp:Label ID="Label4" Text='<%#Bind("ACPhone") %>' runat="server"></asp:Label>
</td>
</tr>
<%-- <tr>
<td style="font-weight: bold;">
Previous Quarter Comments:
</td>
<td colspan="3">
<asp:Label ID="lblPQComments" Text='<%#Bind("PQComments") %>' runat="server" ></asp:Label>
</td>
</tr>--%>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</fieldset>
</div>
</asp:Panel>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</NestedViewTemplate>
</MasterTableView>
<ClientSettings>
<Scrolling AllowScroll="true" SaveScrollPosition="true" UseStaticHeaders = "true" />
</ClientSettings>
<GroupingSettings CaseSensitive="false" />
</telerik:RadGrid>
--------------------------------------------------- code behind ---------------------------------------------------
public void txtBxComments_OnTextChanged(object sender, EventArgs e)
{
TextBox txtComments = (TextBox)sender;
GridDataItem item = (GridDataItem)txtComments.NamingContainer;
//Remove existing key-value pair if reediting the controls
if (reviewListChanges.Count > 0)
{
foreach (KeyValuePair<string, string> pair in reviewListChanges)
{
string[] keyValue = pair.Value.Split('|');
if (pair.Key.Equals(item["AccessReviewID"].Text) && keyValue[0].Equals("TextBox"))
{
reviewListChanges.Remove(pair);
break;
}
}
}
reviewListChanges.Add(new KeyValuePair<string, string>(item["AccessReviewID"].Text, "TextBox" + "|" + txtComments.Text));
}
protected void rgPhysicalAccessReviewList_ItemDataBound(object sender, GridItemEventArgs e)
{
try
{
if ((e.Item is GridDataItem))
{
if (reviewListChanges.Count > 0)
{
foreach (KeyValuePair<string, string> pair in reviewListChanges)
{
string[] keyValue = pair.Value.Split('|');
if (pair.Key.Equals(gridEditFormItem.OwnerTableView.DataKeyValues[gridEditFormItem.ItemIndex]["AccessReviewID"].ToString()))
{
if (keyValue[0] == "TextBox")
{
txtBx.Text = keyValue[1];
}
else
{
ddlList.SelectedValue = keyValue[1];
}
}
}
}
}
}
| 2013-04-26
10:01:37.923,0000000F,OPSWeb,Unhandled Application Exception [Page Info:
/OPSWeb/OPSMain.aspx],Error,Unable to cast object of type
'Telerik.Web.UI.CompressedPageState' to type
'System.Collections.IDictionary'. |
10:21 |