Hi All,
I am exporting Grid and Child grid inside it it is working fine for excel but child grid is not exporting in word format . please let me know what I am doing wrong . My code is
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/.master" AutoEventWireup="true"
CodeFile="Sample.aspx.cs" Inherits="Sample"
EnableEventValidation="false" MaintainScrollPositionOnPostback="true" EnableViewState="true" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder_Content" runat="Server">
<telerik:RadCodeBlock ID="RadCodeBlock" runat="server">
<script type="text/javascript">
var setScrollPosistion = true;
var top = 0;
function DisableAjax(eventTarget, eventArgument) {
$find('<%=RadAjaxManager.GetCurrent(Page).ClientID %>').__doPostBack(eventTarget, eventArgument);
}
function RefreshsampleRadGrid() {
setScrollPosistion = false;
var radMgr = $find('<%=RadAjaxManager.GetCurrent(Page).ClientID %>');
radMgr.ajaxRequest("sampleRadGrid");
return false;
}
</script>
</telerik:RadCodeBlock>
<telerik:RadAjaxManagerProxy ID="radAjaxManagerProxy" runat="server">
</telerik:RadAjaxManagerProxy>
<telerik:RadSplitter ID="splitterMain" runat="server">
<telerik:RadSplitBar ID="RadSplitBar" runat="server">
</telerik:RadSplitBar>
<telerik:RadPane ID="SampleBottomRadPane" runat="server" >
<telerik:RadDockLayout ID="SAmpleRadDockLayout" runat="server" >
<asp:Label ID="MessageLabel" runat="server" ></asp:Label>
<telerik:RadDockZone BStyle="None" ID="SampleRadDockZone" runat="server">
<telerik:RadDock ID="RadDock" runat="server" OnCommand="RadDock_Command">
<TitlebarTemplate>
<table class="RadDockTitlebarTemplateTableClass">
<tr>
<td>
<asp:Label ID="DetailTitleLabel" runat="server"/>
</td>
</tr>
</table>
</TitlebarTemplate>
<Commands>
<telerik:DockExpandCollapseCommand />
<telerik:DockCommand Text="Save Position" AutoPostBack="true" />
</Commands>
</telerik:RadDock>
<telerik:RadDock ID="SampleRadDock" runat="server" OnCommand="RadDock_Command">
<TitlebarTemplate>
<table class="RadDockTitlebarTemplateTableClass">
<tr>
<td>
<asp:Label ID="TitleLabel" runat="server" Text="Text"/>
</td>
</tr>
</table>
</TitlebarTemplate>
<ContentTemplate>
<asp:Panel ID="SearchPanel" runat="server" Width="99.4%">
<div class="RadGridHorizontalScroll" style="overflow: auto;">
<table width="115%">
<tr>
<td style="white-space: nowrap">
<asp:LinkButton ID="ExpandCollapseAllLinkButton" runat="server" Text="Expand/Collapse All"
OnClick="ExpandCollapseAllLinkButton_Click"
Enabled="false"></asp:LinkButton>
<asp:Label ID="TotalLabel" runat="server" Text=" Total:" ></asp:Label>
<asp:Label ID="TotalValueLabel" runat="server" ></asp:Label>
<asp:Label ID="AvailableLabel" runat="server" Text="PO Available:" ></asp:Label>
<asp:Label ID="AvailableValueLabel" runat="server" ></asp:Label>
</td>
</tr>
<tr>
<td>
<telerik:RadGrid ID="sampleRadGrid" runat="server" OnItemCreated="sampleRadGrid_ItemCreated" OnExcelMLExportRowCreated="sampleRadGrid_ExcelMLExportRowCreated"
OnNeedDataSource="sampleRadGrid_NeedDataSource" ShowFooter="true" FooterStyle-Wrap="false"
OnItemDataBound="sampleRadGrid_ItemDataBound" OnDetailTableDataBind="sampleRadGrid_DetailTableDataBind" MasterTableView-ShowGroupFooter="true">
<ExportSettings Excel-Format="ExcelML"/>
<MasterTableView CommandItemDisplay="Top" DataKeyNames="ID,dueAmt,Qty"
HierarchyDefaultExpanded="false" HierarchyLoadMode="Client" TableLayout="Fixed" ShowGroupFooter="true">
<ExpandCollapseColumn Visible="False">
</ExpandCollapseColumn>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<GroupFooterTemplate>
<table width="100%">
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="SubTotalLabel" Text=" Average:"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="TotalRadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="3" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="Label" Text=":"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="RadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="3" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="TaxesLabel" Text="Taxes:"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="TaxesRadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="3" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="TotalLabel" Text=" Total:"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="subTotalRadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="2" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
</table>
</GroupFooterTemplate>
<CommandItemTemplate>
<table width="100%">
<tr>
<td align="left">
<asp:Image ID="ItemImage" runat="server" ></asp:Image>
<asp:HyperLink ID="ItemHyperLink" runat="server" >Add New Item</asp:HyperLink>
</td>
<td class="ExportButtonIconSaperator" style="width: 2%">
<asp:ImageButton ID="ExportToExcelImageButton" Style="margin-right: 0px;"
runat="server" OnClick="ExportToExcelImageButton_Click" />
</td>
<td class="ExportButtonIconSaperator" style="width: 2%">
<asp:ImageButton ID="ExportToWordImageButton"
runat="server" OnClick="ExportToWordImageButton_Click" />
</td>
<td class="ExportButtonIconSaperator" style="width: 2%">
<asp:ImageButton ID="ExportToCsvImageButton"
runat="server" OnClick="ExportToCsvImageButton_Click" />
</td>
</tr>
</table>
</CommandItemTemplate>
<Columns>
<telerik:GridTemplateColumn UniqueName="TemplateEditDeleteColumn" HeaderText="Action">
<HeaderStyle Wrap="false" Width="60px" />
<ItemStyle Wrap="false" />
<ItemTemplate>
<asp:HyperLink ID="ItemHyperLink" runat="server" Text="Edit" ></asp:HyperLink>
<asp:HyperLink ID="CancelHyperLink" runat="server" Text="Cancel" ></asp:HyperLink>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="Reference" HeaderText="Line Item">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="true" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Number" HeaderText="Number">
<HeaderStyle Wrap="false" Width="110px" />
<ItemStyle Wrap="true" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name" HeaderText="Name">
<HeaderStyle Wrap="false" Width="110px" />
<ItemStyle Wrap="true" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Qty" HeaderText="Qty">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="true" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Unit" HeaderText="Unit">
<HeaderStyle Wrap="false" Width="50px" />
<ItemStyle Wrap="true" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="UnitPrice" HeaderText="Unit Price" DataFormatString="{0:0.000}" FooterStyle-HorizontalAlign="Right" FooterAggregateFormatString="{0:0.000}">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="false" HorizontalAlign="Right" />
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Average" UniqueName="Average" SortExpression="Subtotal" FooterStyle-HorizontalAlign="Right" FooterAggregateFormatString="{0:0.000}">
<HeaderStyle Wrap="false" Width="230px" />
<ItemStyle Wrap="false" HorizontalAlign="Right" />
<ItemTemplate>
<asp:Label runat="server" ID="SubtotalLabel" Text='<%#Eval("Subtotal") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<table width="100%">
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="SubTotalLabel" Text=" Average:"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="TotalRadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="3" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="Label" Text=":"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="ShippingRadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="3" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="TaxesLabel" Text="Taxes:"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="TaxesRadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="3" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="TotalLabel" Text=" Total:"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="subTotalRadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="2" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
</table>
</FooterTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="field1" HeaderText="field1" DataFormatString="{0:0.000}">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="true" HorizontalAlign="Right" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="AppliedTaxRate" HeaderText="Tax" DataFormatString="{0:0.000}">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="false" HorizontalAlign="Right" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DeliveryDate" HeaderText="Delivery Date">
<HeaderStyle Wrap="false" Width="90px" />
<ItemStyle Wrap="false" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="dueAmt" HeaderText="Due Qty">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="false" />
</telerik:GridBoundColumn>
</Columns>
<DetailTables>
<telerik:GridTableView runat="server" Name="OtherCharges" CommandItemDisplay="Top"
DataKeyNames="ItemID, ChargeID" ShowHeader="true" TableLayout="Fixed">
<CommandItemTemplate>
<table width="100%">
<tr>
<td align="left">
<asp:Image ID="ChargeImage" runat="server" ></asp:Image>
<asp:HyperLink ID="AddOtherChargeHyperLink" runat="server"
Text="Add Charges to Line Item"></asp:HyperLink>
</td>
</tr>
</table>
</CommandItemTemplate>
<Columns>
<telerik:GridTemplateColumn UniqueName="EditColumn" HeaderText="Action">
<HeaderStyle Wrap="false" Width="60px" />
<ItemStyle Wrap="false" />
<ItemTemplate>
<asp:HyperLink ID="EditHyperLink" runat="server" Text="Edit" ></asp:HyperLink>
</ItemTemplate>
</telerik:GridTemplateColumn>
<HeaderStyle Wrap="false" Width="50px" />
<ItemStyle Wrap="false" HorizontalAlign="Right" />
</telerik:GridBoundColumn>--%>
<telerik:GridBoundColumn DataField="UnitPrice" HeaderText="Unit Price" DataFormatString="{0:0.000}">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="false" HorizontalAlign="Right" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Average" HeaderText="Average">
<ItemStyle Wrap="false" HorizontalAlign="Right" />
<HeaderStyle Wrap="false" Width="230px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="" HeaderText="" EmptyDataText="0.000">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="false" HorizontalAlign="Right" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="AppliedTaxRate" HeaderText="Tax" DataFormatString="{0:0.000}">
<ItemStyle Wrap="false" HorizontalAlign="Right" />
<HeaderStyle Wrap="false" Width="80px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ChargeID" Display="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Abc" HeaderText=" " EmptyDataText=" " Groupable="false" Reable="false" AllowSorting="false">
<ItemStyle Wrap="false" />
<HeaderStyle Wrap="false" Width="640px" />
</telerik:GridBoundColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
</MasterTableView>
</telerik:RadGrid>
</td>
</tr>
</table>
</div>
</asp:Panel>
</ContentTemplate>
<Commands>
<telerik:DockExpandCollapseCommand />
<telerik:DockCommand Text="Save Position" AutoPostBack="true" />
</Commands>
</telerik:RadDock>
</telerik:RadDockZone>
</telerik:RadDockLayout>
<telerik:RadWindowManager ID="AddEditRadWindowManager" runat="server">
<Windows>
<telerik:RadWindow ID="ItemAddDialog" Title="LineItem Add" Left="150px"
runat="server" />
<telerik:RadWindow ID="ItemEditDialog" Title="LineItem Edit" Left="150px"
runat="server" />
<telerik:RadWindow ID="ChargeAddDialog" Title="OtherCharge Add" Left="150px"
runat="server" />
<telerik:RadWindow ID="ChargeEditDialog" Title="OtherCharge Edit"
Left="150px" runat="server" />
</Windows>
</telerik:RadWindowManager>
</telerik:RadPane>
</telerik:RadSplitter>
</asp:Content>
And my code behind is
public partial class Sample
{
protected void Page_Init(object sender, EventArgs e)
{
AddCustomPager(sampleRadGrid);
}
protected void Page_Load(object sender, EventArgs e)
{
radAjaxManagerProxy.AjaxSettings.AddAjaxSetting(radAjaxManagerProxy, sampleRadGrid);
radAjaxManagerProxy.AjaxSettings.AddAjaxSetting(sampleRadGrid, sampleRadGrid);
radAjaxManagerProxy.AjaxSettings.AddAjaxSetting(ExpandCollapseAllLinkButton, sampleRadGrid);
}
protected void sampleRadGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
Decimal liSubtotal = 0;
Decimal liCharges = 0;
Decimal liTaxes = 0;
Decimal liTotal = 0;
DataRow lineItemRow;
Decimal unitPrice = 0M;
Decimal Qty = 0M;
Record = GetOrder(true);
if (Record != null)
{
foreach (ItemInfo item in Record.ItemInfoList)
{
unitPrice = Math.Round(item.UnitPrice, 3);
Qty = Math.Round(item.Qty, 3);
lineItemRow = ItemDataTable.NewRow();
lineItemRow["recordId"] = item.recordId;
lineItemRow["ID"] = item.Id;
lineItemRow["RecordName"] = item.RecordName;
lineItemRow["Comment"] = item.Comment;
lineItemRow["Qty"] = Qty;
lineItemRow["UnitPrice"] = unitPrice;
lineItemRow["Subtotal"] = Math.Round(Qty * unitPrice, 3);
lineItemRow["Date"] = item.Date.ToShortDateString();
lineItemRow["Charges"] = Math.Round(item.Charges, 3);
}
if (Record.PurchaseId.HasValue)
{
try
{
}
catch (Exception ex)
{
}
}
else
{
AvailableLabel.Visible = false;
AvailableValueLabel.Visible = false;
}
sampleRadGrid.DataSource = _lineItemDataTable;
sampleRadGrid.DataMember = "items";
liTotal = Math.Round(liSubtotal + liCharges + liTaxes, 3);
_totalChargesValue = liCharges;
_totalSubtotalValue = liSubtotal;
_totalTaxesValue = liTaxes;
RecordTotalValue = liTotal;
TotalValueLabel.Text = liTotal.ToString();
}
}
protected void sampleRadGrid_ItemCreated(object sender, GridItemEventArgs e)
{
if (_requireReload)
{
Record = GetOrder(false);
GridDataItem dataItem = e.Item as GridDataItem;
if (e.Item.OwnerTableView.DataMember == "items" && e.Item is GridDataItem)
{
}
//details table edit hyperlink
else if (e.Item is GridDataItem)
{
}
else if (e.Item is GridCommandItem)
{
if (e.Item.OwnerTableView.DataMember == "items")
{
}
else
{
HyperLink otherChargeHyperLink = e.Item.FindControl("OtherChargeHyperLink") as HyperLink;
if (otherChargeHyperLink != null)
{
Int32 DueAmt = Convert.ToInt32(e.Item.OwnerTableView.ParentItem.GetDataKeyValue("DueAmt"));
Int32 Qty = Convert.ToInt32(e.Item.OwnerTableView.ParentItem.GetDataKeyValue("Qty"));
otherChargeHyperLink.Enabled = (DueAmt == Qty);
if (PartPermission.Check(PartPerm.PartOrderItems) && Record.OrderReceiveStatus.Equals(OrderReceiveStatus.Open.ToString()) && otherChargeHyperLink.Enabled)
{
otherChargeHyperLink.Attributes["href"] = "#";
}
}
}
}
HyperLink LineItemHyperLink = e.Item.FindControl("LineItemHyperLink") as HyperLink;
if (LineItemHyperLink != null)
{
if (PartPermission.Check(PartPerm.PartOrderItems) && Record.OrderReceiveStatus.Equals(OrderReceiveStatus.Open.ToString()))
{
LineItemHyperLink.Attributes["href"] = "#";
}
}
foreach (GridItem item in sampleRadGrid.MasterTableView.Controls[0].Controls)
{
if (!_isFirstTime)
{
if (ViewState["Expanded"] == null)
item.Expanded = false;
else
item.Expanded = true;
}
if (_isFirstTime)
ViewState["Expanded"] = null;
}
}
}
protected void sampleRadGrid_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
{
if (_requireReload)
{
GridDataItem gridDataItem = e.DetailTableView.ParentItem as GridDataItem;
if (gridDataItem != null)
{
Int32 recordId = 0;
Int32.TryParse(gridDataItem.GetDataKeyValue("recordId").ToString(), out recordId);
if (recordId != 0)
{
try
{
DataTable chargesDataTable = new DataTable("chargesDataTable");
chargesDataTable.Columns.Add(new DataColumn("ChargeID"));
chargesDataTable.Columns.Add(new DataColumn("recordId"));
chargesDataTable.Columns.Add(new DataColumn("ChargeType"));
chargesDataTable.Columns.Add(new DataColumn("AppliedTaxRate", System.Type.GetType("System.Decimal")));
chargesDataTable.Columns.Add(new DataColumn("UnitPrice", System.Type.GetType("System.Decimal")));
chargesDataTable.Columns.Add(new DataColumn("average", System.Type.GetType("System.Decimal")));
chargesDataTable.Columns.Add(new DataColumn("Charges", System.Type.GetType("System.Decimal")));
ChargeInfoList ChargeInfoList = ChargeInfoList.GetInfoList(recordId);
DataRow OtherChargesRow;
foreach (ChargeInfo otherItem in ChargeInfoList)
{
ItemInfo ItemInfo = ItemInfo.GetInfo(recordId);
OtherChargesRow = chargesDataTable.NewRow();
OtherChargesRow["OrderOtherChargeID"] = otherItem.OrderOtherChargeID;
OtherChargesRow["recordId"] = otherItem.recordId;
OtherChargesRow["ChargeType"] = otherItem.OtherChargeType;
OtherChargesRow["UnitPrice"] = Math.Round(otherItem.UnitPrice, 3);
OtherChargesRow["AppliedTaxRate"] = Math.Round(otherItem.AppliedTaxRate, 3);
OtherChargesRow["average"] = Math.Round(ItemInfo.Qty * otherItem.UnitPrice, 3);
OtherChargesRow["Charges"] = 0.00;
chargesDataTable.Rows.Add(ChargesRow);
}
e.DetailTableView.DataSource = chargesDataTable;
e.DetailTableView.DataMember = "OtherCharges";
}
catch (Exception ex)
{
}
}
}
}
}
private void InitializeGrid()
{
if (_requireReload)
{
_lineItemDataTable = new DataTable("LineItemsDataTable");
_lineItemDataTable.Columns.Add(new DataColumn("recordId"));
_lineItemDataTable.Columns.Add(new DataColumn("Id"));
_lineItemDataTable.Columns.Add(new DataColumn("Reference"));
_lineItemDataTable.Columns.Add(new DataColumn("Number"));
_lineItemDataTable.Columns.Add(new DataColumn("PartID"));
_lineItemDataTable.Columns.Add(new DataColumn("RecordName"));
_lineItemDataTable.Columns.Add(new DataColumn("Comment"));
_lineItemDataTable.Columns.Add(new DataColumn("Qty", System.Type.GetType("System.Decimal")));
_lineItemDataTable.Columns.Add(new DataColumn("UnitMeasure"));
_lineItemDataTable.Columns.Add(new DataColumn("UnitPrice", System.Type.GetType("System.Decimal")));
_lineItemDataTable.Columns.Add(new DataColumn("Subtotal", System.Type.GetType("System.Decimal")));
_lineItemDataTable.Columns.Add(new DataColumn("Date"));
_lineItemDataTable.Columns.Add(new DataColumn("DueAmt", System.Type.GetType("System.Decimal")));
_lineItemDataTable.Columns.Add(new DataColumn("Charges", System.Type.GetType("System.Decimal")));
_lineItemDataTable.Columns.Add(new DataColumn("AppliedTaxRate", System.Type.GetType("System.Decimal")));
}
}
protected void sampleRadGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
if (_requireReload)
{
Decimal Qty = 0;
Decimal DueAmt = 0;
Record = GetOrder(false);
if (e.Item is GridDataItem)
{
Decimal ItemTotalValue = 0;
Decimal ChargesTotalValue = 0;
if (e.Item.OwnerTableView.DataMember.Equals("items"))
{
GridDataItem dataItem = e.Item as GridDataItem;
Decimal ChargesValue = Convert.ToDecimal(dataItem["Charges"].Text);
Decimal subtotalValue = 0;
Label TotalLabel = dataItem["Average"].FindControl("TotalLabel") as Label;
if (TotalLabel != null)
subtotalValue = Convert.ToDecimal(TotalLabel.Text);
Decimal taxesValue = Convert.ToDecimal(dataItem["AppliedTaxRate"].Text);
orderLineItemTotalValue = ChargesValue + subtotalValue + taxesValue;
HyperLink cancelLineItemLink = e.Item.FindControl("CancelItemHyperLink") as HyperLink;
DueAmt = Convert.ToDecimal(dataItem["DueAmt"].Text);
Qty = Convert.ToDecimal(dataItem["Qty"].Text);
}
if (e.Item.OwnerTableView.DataMember.Equals("OtherCharges"))
{
Decimal totalTaxesOtherCharge = 0;
GridDataItem dataItem = e.Item as GridDataItem;
Decimal subtotalOtherChargeValue = 0;
subtotalOtherChargeValue = Convert.ToDecimal(dataItem["Average"].Text);
totalTaxesOtherCharge += Convert.ToDecimal(dataItem["AppliedTaxRate"].Text);
orderOtherChargesTotalValue = subtotalOtherChargeValue + totalTaxesOtherCharge;
HyperLink editOtherChargeLink = e.Item.FindControl("EditChargeHyperLink") as HyperLink;
DueAmt = Convert.ToInt32(e.Item.OwnerTableView.ParentItem.GetDataKeyValue("DueAmt"));
Qty = Convert.ToInt32(e.Item.OwnerTableView.ParentItem.GetDataKeyValue("Qty"));
}
}
if (e.Item is GridFooterItem && e.Item.OwnerTableView.DataMember.Equals("items"))
{
GridFooterItem footerItem = e.Item as GridFooterItem;
if (footerItem != null)
{
RadNumericTextBox TotalRadNumericTextBox = footerItem.FindControl("TotalRadNumericTextBox") as RadNumericTextBox;
if (TotalRadNumericTextBox != null)
TotalRadNumericTextBox.Text = Math.Round(_totalSubtotalValue, 3).ToString();
RadNumericTextBox ChargesRadNumericTextBox = footerItem.FindControl("ChargesRadNumericTextBox") as RadNumericTextBox;
if (ChargesRadNumericTextBox != null)
ChargesRadNumericTextBox.Text = Math.Round(_totalChargesValue, 3).ToString();
RadNumericTextBox taxesRadNumericTextBox = footerItem.FindControl("TaxesRadNumericTextBox") as RadNumericTextBox;
if (taxesRadNumericTextBox != null)
taxesRadNumericTextBox.Text = Math.Round(_totalTaxesValue, 3).ToString();
RadNumericTextBox subTotalRadNumericTextBox = footerItem.FindControl("subTotalRadNumericTextBox") as RadNumericTextBox;
if (subTotalRadNumericTextBox != null)
subTotalRadNumericTextBox.Text = Math.Round((RecordTotalValue), 2).ToString();
}
}
}
}
protected void ExpandCollapseAllLinkButton_Click(object sender, EventArgs e)
{
foreach (GridItem item in sampleRadGrid.MasterTableView.Controls[0].Controls)
{
if (ViewState["Expanded"] == null)
item.Expanded = true;
else
item.Expanded = false;
}
if (ViewState["Expanded"] != null)
ViewState["Expanded"] = null;
else
ViewState["Expanded"] = true;
sampleRadGrid.MasterTableView.ShowFooter = true;
}
protected void ExportToExcelImageButton_Click(object sender, EventArgs e)
{
ExportDataToFile();
ExportToExcel(sampleRadGrid, "SampleGridData");
}
protected void ExportToWordImageButton_Click(object sender, EventArgs e)
{
ExportDataToFile();
ExportToWord(sampleRadGrid, "SampleGridData");
}
protected void ExportToCsvImageButton_Click(object sender, EventArgs e)
{
ExportDataToFile();
ExportToCsv(sampleRadGrid, "SampleGridData");
}
private void ExportDataToFile()
{
sampleRadGrid.MasterTableView.ExpandCollapseColumn.Display = false;
sampleRadGrid.MasterTableView.DetailTables[0].ExpandCollapseColumn.Display = false;
sampleRadGrid.MasterTableView.DetailTables[0].CommandItemDisplay = GridCommandItemDisplay.None;
sampleRadGrid.ShowFooter = true;
sampleRadGrid.MasterTableView.DetailTables[0].ShowFooter = true;
}
protected void Page_PreRender(object sender, System.EventArgs e)
{
GridItem commandItem = sampleRadGrid.MasterTableView.GetItems(GridItemType.CommandItem)[0];
ImageButton exportToExcelImageButton = commandItem.FindControl("ExportToExcelImageButton") as ImageButton;
ImageButton exportToWordImageButton = commandItem.FindControl("ExportToWordImageButton") as ImageButton;
ImageButton exportToCsvImageButton = commandItem.FindControl("ExportToCsvImageButton") as ImageButton;
if (sampleRadGrid.Items.Count > 0)
{
if (_isFirstTime)
_isFirstTime = false;
}
ExpandCollapseAllLinkButton.Enabled = sampleRadGrid.MasterTableView.Items.Count > 0;
if (ExpandCollapseAllLinkButton != null)
ExpandCollapseAllLinkButton.Enabled = sampleRadGrid.Items.Count > 0;
OrderDetailDetailMenu.PrintOrderPrintLinkButtonControl.Enabled = sampleRadGrid.Items.Count > 0;
Boolean isGridHasData = sampleRadGrid.Items.Count > 0;
if (exportToExcelImageButton != null)
{
exportToExcelImageButton.Enabled = isGridHasData;
if (exportToExcelImageButton.Enabled)
{
exportToExcelImageButton.Attributes.Add("onclick", String.Format("DisableAjax(\"{0}\", \"\"); return false;", exportToExcelImageButton.UniqueID));
exportToExcelImageButton.Style.Add(StringResources.CssCursorKey, StringResources.CssCursorValue);
}
}
if (exportToWordImageButton != null)
{
exportToWordImageButton.Enabled = isGridHasData;
if (exportToWordImageButton.Enabled)
{
exportToWordImageButton.Attributes.Add("onclick", String.Format("DisableAjax(\"{0}\", \"\"); return false;", exportToWordImageButton.UniqueID));
exportToWordImageButton.Style.Add(StringResources.CssCursorKey, StringResources.CssCursorValue);
}
}
if (exportToCsvImageButton != null)
{
exportToCsvImageButton.Enabled = isGridHasData;
if (exportToCsvImageButton.Enabled)
{
exportToCsvImageButton.Attributes.Add("onclick", String.Format("DisableAjax(\"{0}\", \"\"); return false;", exportToCsvImageButton.UniqueID));
exportToCsvImageButton.Style.Add(StringResources.CssCursorKey, StringResources.CssCursorValue);
}
}
}
private Info GetOrder(Boolean clearCache)
{
if (_requireReload)
{
try
{
String cacheName = String.Format("Order{0}{1}", RecordID, _guid);
if (!clearCache && CacheObject[cacheName] != null)
return (Info)CacheObject[cacheName];
else
{
Info Info = Info.GetInfo(RecordID, true);
AddCache(cacheName, Info);
HiddenLabel.Text = RecordID.ToString();
DetailTitleLabel.Text = String.Format("Order {0}", RecordID);
DetailHeaderLabel.Text = String.Format("Created By {0} {1}", Info.OrderedByFirstName, Info.OrderedByLastName);
return Info;
}
}
catch (Exception ex)
{
}
}
return null;
}
}
protected void AddCustomPager(RadGrid radGrid)
{
radGrid.PageSize = 10;
radGrid.AllowPaging = true;
radGrid.MasterTableView.PagerStyle.AlwaysVisible = true;
foreach (GridTableView gridTableView in radGrid.MasterTableView.DetailTables)
{
gridTableView.PageSize = 10;
gridTableView.AllowPaging = true;
gridTableView.PagerStyle.AlwaysVisible = true;
}
radGrid.ItemCreated += new GridItemEventHandler(RadGrid_ItemCreated);
if (radGrid.ID != "InformationRadGrid")
radGrid.ItemCommand += new GridCommandEventHandler(RadGrid_ItemCommand);
}
protected void ExportToExcel(RadGrid searchRadGrid, String fileName)
{
searchRadGrid.MasterTableView.HierarchyDefaultExpanded = true;
if (searchRadGrid.MasterTableView.HasDetailTables)
{
foreach (GridTableView gridTableView in searchRadGrid.MasterTableView.DetailTables)
{
gridTableView.AllowPaging = false;
gridTableView.HierarchyDefaultExpanded = true;
}
}
searchRadGrid.ExcelExportCellFormatting += new OnExcelExportCellFormattingEventHandler(SearchRadGrid_ExcelExportCellFormatting);
searchRadGrid.ItemCreated += new GridItemEventHandler(RadGrid_ItemCreated);
searchRadGrid.ExportSettings.ExportOnlyData = true;
searchRadGrid.ExportSettings.IgnorePaging = true;
searchRadGrid.ExportSettings.OpenInNewWindow = true;
searchRadGrid.ExportSettings.FileName = fileName;
_isExport = true;
searchRadGrid.MasterTableView.ExportToExcel();
}
protected void ExportToWord(RadGrid searchRadGrid, String fileName)
{
searchRadGrid.MasterTableView.HierarchyDefaultExpanded = true;
if (searchRadGrid.MasterTableView.HasDetailTables)
{
foreach (GridTableView gridTableView in searchRadGrid.MasterTableView.DetailTables)
{
gridTableView.AllowPaging = false;
gridTableView.HierarchyDefaultExpanded = true;
}
}
searchRadGrid.ItemCreated += new GridItemEventHandler(RadGrid_ItemCreated);
searchRadGrid.ExportSettings.ExportOnlyData = true;
searchRadGrid.ExportSettings.IgnorePaging = true;
searchRadGrid.ExportSettings.OpenInNewWindow = true;
searchRadGrid.ExportSettings.FileName = fileName;
_isExport = true;
searchRadGrid.MasterTableView.ExportToWord();
}
protected void ExportToCsv(RadGrid searchRadGrid, String fileName)
{
if (searchRadGrid.MasterTableView.HasDetailTables)
{
foreach (GridTableView gridTableView in searchRadGrid.MasterTableView.DetailTables)
gridTableView.HierarchyDefaultExpanded = true;
}
searchRadGrid.MasterTableView.HierarchyDefaultExpanded = true;
searchRadGrid.GridExporting += new OnGridExportingEventHandler(RadGrid_GridExporting); // Defect - 9405 - 21 Jun 2011 - By Partner CB
searchRadGrid.ItemCreated += new GridItemEventHandler(RadGrid_ItemCreated);
searchRadGrid.ExportSettings.ExportOnlyData = isExportOnlydata;
searchRadGrid.ExportSettings.IgnorePaging = true;
searchRadGrid.ExportSettings.OpenInNewWindow = true;
searchRadGrid.ExportSettings.FileName = fileName;
_isExport = true;
searchRadGrid.MasterTableView.ExportToCSV();
}
Thanks
I am exporting Grid and Child grid inside it it is working fine for excel but child grid is not exporting in word format . please let me know what I am doing wrong . My code is
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/.master" AutoEventWireup="true"
CodeFile="Sample.aspx.cs" Inherits="Sample"
EnableEventValidation="false" MaintainScrollPositionOnPostback="true" EnableViewState="true" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder_Content" runat="Server">
<telerik:RadCodeBlock ID="RadCodeBlock" runat="server">
<script type="text/javascript">
var setScrollPosistion = true;
var top = 0;
function DisableAjax(eventTarget, eventArgument) {
$find('<%=RadAjaxManager.GetCurrent(Page).ClientID %>').__doPostBack(eventTarget, eventArgument);
}
function RefreshsampleRadGrid() {
setScrollPosistion = false;
var radMgr = $find('<%=RadAjaxManager.GetCurrent(Page).ClientID %>');
radMgr.ajaxRequest("sampleRadGrid");
return false;
}
</script>
</telerik:RadCodeBlock>
<telerik:RadAjaxManagerProxy ID="radAjaxManagerProxy" runat="server">
</telerik:RadAjaxManagerProxy>
<telerik:RadSplitter ID="splitterMain" runat="server">
<telerik:RadSplitBar ID="RadSplitBar" runat="server">
</telerik:RadSplitBar>
<telerik:RadPane ID="SampleBottomRadPane" runat="server" >
<telerik:RadDockLayout ID="SAmpleRadDockLayout" runat="server" >
<asp:Label ID="MessageLabel" runat="server" ></asp:Label>
<telerik:RadDockZone BStyle="None" ID="SampleRadDockZone" runat="server">
<telerik:RadDock ID="RadDock" runat="server" OnCommand="RadDock_Command">
<TitlebarTemplate>
<table class="RadDockTitlebarTemplateTableClass">
<tr>
<td>
<asp:Label ID="DetailTitleLabel" runat="server"/>
</td>
</tr>
</table>
</TitlebarTemplate>
<Commands>
<telerik:DockExpandCollapseCommand />
<telerik:DockCommand Text="Save Position" AutoPostBack="true" />
</Commands>
</telerik:RadDock>
<telerik:RadDock ID="SampleRadDock" runat="server" OnCommand="RadDock_Command">
<TitlebarTemplate>
<table class="RadDockTitlebarTemplateTableClass">
<tr>
<td>
<asp:Label ID="TitleLabel" runat="server" Text="Text"/>
</td>
</tr>
</table>
</TitlebarTemplate>
<ContentTemplate>
<asp:Panel ID="SearchPanel" runat="server" Width="99.4%">
<div class="RadGridHorizontalScroll" style="overflow: auto;">
<table width="115%">
<tr>
<td style="white-space: nowrap">
<asp:LinkButton ID="ExpandCollapseAllLinkButton" runat="server" Text="Expand/Collapse All"
OnClick="ExpandCollapseAllLinkButton_Click"
Enabled="false"></asp:LinkButton>
<asp:Label ID="TotalLabel" runat="server" Text=" Total:" ></asp:Label>
<asp:Label ID="TotalValueLabel" runat="server" ></asp:Label>
<asp:Label ID="AvailableLabel" runat="server" Text="PO Available:" ></asp:Label>
<asp:Label ID="AvailableValueLabel" runat="server" ></asp:Label>
</td>
</tr>
<tr>
<td>
<telerik:RadGrid ID="sampleRadGrid" runat="server" OnItemCreated="sampleRadGrid_ItemCreated" OnExcelMLExportRowCreated="sampleRadGrid_ExcelMLExportRowCreated"
OnNeedDataSource="sampleRadGrid_NeedDataSource" ShowFooter="true" FooterStyle-Wrap="false"
OnItemDataBound="sampleRadGrid_ItemDataBound" OnDetailTableDataBind="sampleRadGrid_DetailTableDataBind" MasterTableView-ShowGroupFooter="true">
<ExportSettings Excel-Format="ExcelML"/>
<MasterTableView CommandItemDisplay="Top" DataKeyNames="ID,dueAmt,Qty"
HierarchyDefaultExpanded="false" HierarchyLoadMode="Client" TableLayout="Fixed" ShowGroupFooter="true">
<ExpandCollapseColumn Visible="False">
</ExpandCollapseColumn>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<GroupFooterTemplate>
<table width="100%">
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="SubTotalLabel" Text=" Average:"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="TotalRadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="3" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="Label" Text=":"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="RadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="3" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="TaxesLabel" Text="Taxes:"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="TaxesRadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="3" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="TotalLabel" Text=" Total:"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="subTotalRadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="2" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
</table>
</GroupFooterTemplate>
<CommandItemTemplate>
<table width="100%">
<tr>
<td align="left">
<asp:Image ID="ItemImage" runat="server" ></asp:Image>
<asp:HyperLink ID="ItemHyperLink" runat="server" >Add New Item</asp:HyperLink>
</td>
<td class="ExportButtonIconSaperator" style="width: 2%">
<asp:ImageButton ID="ExportToExcelImageButton" Style="margin-right: 0px;"
runat="server" OnClick="ExportToExcelImageButton_Click" />
</td>
<td class="ExportButtonIconSaperator" style="width: 2%">
<asp:ImageButton ID="ExportToWordImageButton"
runat="server" OnClick="ExportToWordImageButton_Click" />
</td>
<td class="ExportButtonIconSaperator" style="width: 2%">
<asp:ImageButton ID="ExportToCsvImageButton"
runat="server" OnClick="ExportToCsvImageButton_Click" />
</td>
</tr>
</table>
</CommandItemTemplate>
<Columns>
<telerik:GridTemplateColumn UniqueName="TemplateEditDeleteColumn" HeaderText="Action">
<HeaderStyle Wrap="false" Width="60px" />
<ItemStyle Wrap="false" />
<ItemTemplate>
<asp:HyperLink ID="ItemHyperLink" runat="server" Text="Edit" ></asp:HyperLink>
<asp:HyperLink ID="CancelHyperLink" runat="server" Text="Cancel" ></asp:HyperLink>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="Reference" HeaderText="Line Item">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="true" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Number" HeaderText="Number">
<HeaderStyle Wrap="false" Width="110px" />
<ItemStyle Wrap="true" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name" HeaderText="Name">
<HeaderStyle Wrap="false" Width="110px" />
<ItemStyle Wrap="true" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Qty" HeaderText="Qty">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="true" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Unit" HeaderText="Unit">
<HeaderStyle Wrap="false" Width="50px" />
<ItemStyle Wrap="true" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="UnitPrice" HeaderText="Unit Price" DataFormatString="{0:0.000}" FooterStyle-HorizontalAlign="Right" FooterAggregateFormatString="{0:0.000}">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="false" HorizontalAlign="Right" />
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Average" UniqueName="Average" SortExpression="Subtotal" FooterStyle-HorizontalAlign="Right" FooterAggregateFormatString="{0:0.000}">
<HeaderStyle Wrap="false" Width="230px" />
<ItemStyle Wrap="false" HorizontalAlign="Right" />
<ItemTemplate>
<asp:Label runat="server" ID="SubtotalLabel" Text='<%#Eval("Subtotal") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<table width="100%">
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="SubTotalLabel" Text=" Average:"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="TotalRadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="3" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="Label" Text=":"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="ShippingRadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="3" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="TaxesLabel" Text="Taxes:"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="TaxesRadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="3" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td style="white-space: nowrap">
<asp:Label runat="server" ID="TotalLabel" Text=" Total:"></asp:Label>
</td>
<td>
<telerik:RadNumericTextBox runat="server" ID="subTotalRadNumericTextBox" ReadOnly="true"
Width="100px" EnabledStyle-HorizontalAlign="Right" NumberFormat-DecimalDigits="2" CssClass="AlignedRadNumericTextBox">
</telerik:RadNumericTextBox>
</td>
</tr>
</table>
</FooterTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="field1" HeaderText="field1" DataFormatString="{0:0.000}">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="true" HorizontalAlign="Right" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="AppliedTaxRate" HeaderText="Tax" DataFormatString="{0:0.000}">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="false" HorizontalAlign="Right" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DeliveryDate" HeaderText="Delivery Date">
<HeaderStyle Wrap="false" Width="90px" />
<ItemStyle Wrap="false" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="dueAmt" HeaderText="Due Qty">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="false" />
</telerik:GridBoundColumn>
</Columns>
<DetailTables>
<telerik:GridTableView runat="server" Name="OtherCharges" CommandItemDisplay="Top"
DataKeyNames="ItemID, ChargeID" ShowHeader="true" TableLayout="Fixed">
<CommandItemTemplate>
<table width="100%">
<tr>
<td align="left">
<asp:Image ID="ChargeImage" runat="server" ></asp:Image>
<asp:HyperLink ID="AddOtherChargeHyperLink" runat="server"
Text="Add Charges to Line Item"></asp:HyperLink>
</td>
</tr>
</table>
</CommandItemTemplate>
<Columns>
<telerik:GridTemplateColumn UniqueName="EditColumn" HeaderText="Action">
<HeaderStyle Wrap="false" Width="60px" />
<ItemStyle Wrap="false" />
<ItemTemplate>
<asp:HyperLink ID="EditHyperLink" runat="server" Text="Edit" ></asp:HyperLink>
</ItemTemplate>
</telerik:GridTemplateColumn>
<HeaderStyle Wrap="false" Width="50px" />
<ItemStyle Wrap="false" HorizontalAlign="Right" />
</telerik:GridBoundColumn>--%>
<telerik:GridBoundColumn DataField="UnitPrice" HeaderText="Unit Price" DataFormatString="{0:0.000}">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="false" HorizontalAlign="Right" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Average" HeaderText="Average">
<ItemStyle Wrap="false" HorizontalAlign="Right" />
<HeaderStyle Wrap="false" Width="230px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="" HeaderText="" EmptyDataText="0.000">
<HeaderStyle Wrap="false" Width="80px" />
<ItemStyle Wrap="false" HorizontalAlign="Right" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="AppliedTaxRate" HeaderText="Tax" DataFormatString="{0:0.000}">
<ItemStyle Wrap="false" HorizontalAlign="Right" />
<HeaderStyle Wrap="false" Width="80px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ChargeID" Display="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Abc" HeaderText=" " EmptyDataText=" " Groupable="false" Reable="false" AllowSorting="false">
<ItemStyle Wrap="false" />
<HeaderStyle Wrap="false" Width="640px" />
</telerik:GridBoundColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
</MasterTableView>
</telerik:RadGrid>
</td>
</tr>
</table>
</div>
</asp:Panel>
</ContentTemplate>
<Commands>
<telerik:DockExpandCollapseCommand />
<telerik:DockCommand Text="Save Position" AutoPostBack="true" />
</Commands>
</telerik:RadDock>
</telerik:RadDockZone>
</telerik:RadDockLayout>
<telerik:RadWindowManager ID="AddEditRadWindowManager" runat="server">
<Windows>
<telerik:RadWindow ID="ItemAddDialog" Title="LineItem Add" Left="150px"
runat="server" />
<telerik:RadWindow ID="ItemEditDialog" Title="LineItem Edit" Left="150px"
runat="server" />
<telerik:RadWindow ID="ChargeAddDialog" Title="OtherCharge Add" Left="150px"
runat="server" />
<telerik:RadWindow ID="ChargeEditDialog" Title="OtherCharge Edit"
Left="150px" runat="server" />
</Windows>
</telerik:RadWindowManager>
</telerik:RadPane>
</telerik:RadSplitter>
</asp:Content>
And my code behind is
public partial class Sample
{
protected void Page_Init(object sender, EventArgs e)
{
AddCustomPager(sampleRadGrid);
}
protected void Page_Load(object sender, EventArgs e)
{
radAjaxManagerProxy.AjaxSettings.AddAjaxSetting(radAjaxManagerProxy, sampleRadGrid);
radAjaxManagerProxy.AjaxSettings.AddAjaxSetting(sampleRadGrid, sampleRadGrid);
radAjaxManagerProxy.AjaxSettings.AddAjaxSetting(ExpandCollapseAllLinkButton, sampleRadGrid);
}
protected void sampleRadGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
Decimal liSubtotal = 0;
Decimal liCharges = 0;
Decimal liTaxes = 0;
Decimal liTotal = 0;
DataRow lineItemRow;
Decimal unitPrice = 0M;
Decimal Qty = 0M;
Record = GetOrder(true);
if (Record != null)
{
foreach (ItemInfo item in Record.ItemInfoList)
{
unitPrice = Math.Round(item.UnitPrice, 3);
Qty = Math.Round(item.Qty, 3);
lineItemRow = ItemDataTable.NewRow();
lineItemRow["recordId"] = item.recordId;
lineItemRow["ID"] = item.Id;
lineItemRow["RecordName"] = item.RecordName;
lineItemRow["Comment"] = item.Comment;
lineItemRow["Qty"] = Qty;
lineItemRow["UnitPrice"] = unitPrice;
lineItemRow["Subtotal"] = Math.Round(Qty * unitPrice, 3);
lineItemRow["Date"] = item.Date.ToShortDateString();
lineItemRow["Charges"] = Math.Round(item.Charges, 3);
}
if (Record.PurchaseId.HasValue)
{
try
{
}
catch (Exception ex)
{
}
}
else
{
AvailableLabel.Visible = false;
AvailableValueLabel.Visible = false;
}
sampleRadGrid.DataSource = _lineItemDataTable;
sampleRadGrid.DataMember = "items";
liTotal = Math.Round(liSubtotal + liCharges + liTaxes, 3);
_totalChargesValue = liCharges;
_totalSubtotalValue = liSubtotal;
_totalTaxesValue = liTaxes;
RecordTotalValue = liTotal;
TotalValueLabel.Text = liTotal.ToString();
}
}
protected void sampleRadGrid_ItemCreated(object sender, GridItemEventArgs e)
{
if (_requireReload)
{
Record = GetOrder(false);
GridDataItem dataItem = e.Item as GridDataItem;
if (e.Item.OwnerTableView.DataMember == "items" && e.Item is GridDataItem)
{
}
//details table edit hyperlink
else if (e.Item is GridDataItem)
{
}
else if (e.Item is GridCommandItem)
{
if (e.Item.OwnerTableView.DataMember == "items")
{
}
else
{
HyperLink otherChargeHyperLink = e.Item.FindControl("OtherChargeHyperLink") as HyperLink;
if (otherChargeHyperLink != null)
{
Int32 DueAmt = Convert.ToInt32(e.Item.OwnerTableView.ParentItem.GetDataKeyValue("DueAmt"));
Int32 Qty = Convert.ToInt32(e.Item.OwnerTableView.ParentItem.GetDataKeyValue("Qty"));
otherChargeHyperLink.Enabled = (DueAmt == Qty);
if (PartPermission.Check(PartPerm.PartOrderItems) && Record.OrderReceiveStatus.Equals(OrderReceiveStatus.Open.ToString()) && otherChargeHyperLink.Enabled)
{
otherChargeHyperLink.Attributes["href"] = "#";
}
}
}
}
HyperLink LineItemHyperLink = e.Item.FindControl("LineItemHyperLink") as HyperLink;
if (LineItemHyperLink != null)
{
if (PartPermission.Check(PartPerm.PartOrderItems) && Record.OrderReceiveStatus.Equals(OrderReceiveStatus.Open.ToString()))
{
LineItemHyperLink.Attributes["href"] = "#";
}
}
foreach (GridItem item in sampleRadGrid.MasterTableView.Controls[0].Controls)
{
if (!_isFirstTime)
{
if (ViewState["Expanded"] == null)
item.Expanded = false;
else
item.Expanded = true;
}
if (_isFirstTime)
ViewState["Expanded"] = null;
}
}
}
protected void sampleRadGrid_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
{
if (_requireReload)
{
GridDataItem gridDataItem = e.DetailTableView.ParentItem as GridDataItem;
if (gridDataItem != null)
{
Int32 recordId = 0;
Int32.TryParse(gridDataItem.GetDataKeyValue("recordId").ToString(), out recordId);
if (recordId != 0)
{
try
{
DataTable chargesDataTable = new DataTable("chargesDataTable");
chargesDataTable.Columns.Add(new DataColumn("ChargeID"));
chargesDataTable.Columns.Add(new DataColumn("recordId"));
chargesDataTable.Columns.Add(new DataColumn("ChargeType"));
chargesDataTable.Columns.Add(new DataColumn("AppliedTaxRate", System.Type.GetType("System.Decimal")));
chargesDataTable.Columns.Add(new DataColumn("UnitPrice", System.Type.GetType("System.Decimal")));
chargesDataTable.Columns.Add(new DataColumn("average", System.Type.GetType("System.Decimal")));
chargesDataTable.Columns.Add(new DataColumn("Charges", System.Type.GetType("System.Decimal")));
ChargeInfoList ChargeInfoList = ChargeInfoList.GetInfoList(recordId);
DataRow OtherChargesRow;
foreach (ChargeInfo otherItem in ChargeInfoList)
{
ItemInfo ItemInfo = ItemInfo.GetInfo(recordId);
OtherChargesRow = chargesDataTable.NewRow();
OtherChargesRow["OrderOtherChargeID"] = otherItem.OrderOtherChargeID;
OtherChargesRow["recordId"] = otherItem.recordId;
OtherChargesRow["ChargeType"] = otherItem.OtherChargeType;
OtherChargesRow["UnitPrice"] = Math.Round(otherItem.UnitPrice, 3);
OtherChargesRow["AppliedTaxRate"] = Math.Round(otherItem.AppliedTaxRate, 3);
OtherChargesRow["average"] = Math.Round(ItemInfo.Qty * otherItem.UnitPrice, 3);
OtherChargesRow["Charges"] = 0.00;
chargesDataTable.Rows.Add(ChargesRow);
}
e.DetailTableView.DataSource = chargesDataTable;
e.DetailTableView.DataMember = "OtherCharges";
}
catch (Exception ex)
{
}
}
}
}
}
private void InitializeGrid()
{
if (_requireReload)
{
_lineItemDataTable = new DataTable("LineItemsDataTable");
_lineItemDataTable.Columns.Add(new DataColumn("recordId"));
_lineItemDataTable.Columns.Add(new DataColumn("Id"));
_lineItemDataTable.Columns.Add(new DataColumn("Reference"));
_lineItemDataTable.Columns.Add(new DataColumn("Number"));
_lineItemDataTable.Columns.Add(new DataColumn("PartID"));
_lineItemDataTable.Columns.Add(new DataColumn("RecordName"));
_lineItemDataTable.Columns.Add(new DataColumn("Comment"));
_lineItemDataTable.Columns.Add(new DataColumn("Qty", System.Type.GetType("System.Decimal")));
_lineItemDataTable.Columns.Add(new DataColumn("UnitMeasure"));
_lineItemDataTable.Columns.Add(new DataColumn("UnitPrice", System.Type.GetType("System.Decimal")));
_lineItemDataTable.Columns.Add(new DataColumn("Subtotal", System.Type.GetType("System.Decimal")));
_lineItemDataTable.Columns.Add(new DataColumn("Date"));
_lineItemDataTable.Columns.Add(new DataColumn("DueAmt", System.Type.GetType("System.Decimal")));
_lineItemDataTable.Columns.Add(new DataColumn("Charges", System.Type.GetType("System.Decimal")));
_lineItemDataTable.Columns.Add(new DataColumn("AppliedTaxRate", System.Type.GetType("System.Decimal")));
}
}
protected void sampleRadGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
if (_requireReload)
{
Decimal Qty = 0;
Decimal DueAmt = 0;
Record = GetOrder(false);
if (e.Item is GridDataItem)
{
Decimal ItemTotalValue = 0;
Decimal ChargesTotalValue = 0;
if (e.Item.OwnerTableView.DataMember.Equals("items"))
{
GridDataItem dataItem = e.Item as GridDataItem;
Decimal ChargesValue = Convert.ToDecimal(dataItem["Charges"].Text);
Decimal subtotalValue = 0;
Label TotalLabel = dataItem["Average"].FindControl("TotalLabel") as Label;
if (TotalLabel != null)
subtotalValue = Convert.ToDecimal(TotalLabel.Text);
Decimal taxesValue = Convert.ToDecimal(dataItem["AppliedTaxRate"].Text);
orderLineItemTotalValue = ChargesValue + subtotalValue + taxesValue;
HyperLink cancelLineItemLink = e.Item.FindControl("CancelItemHyperLink") as HyperLink;
DueAmt = Convert.ToDecimal(dataItem["DueAmt"].Text);
Qty = Convert.ToDecimal(dataItem["Qty"].Text);
}
if (e.Item.OwnerTableView.DataMember.Equals("OtherCharges"))
{
Decimal totalTaxesOtherCharge = 0;
GridDataItem dataItem = e.Item as GridDataItem;
Decimal subtotalOtherChargeValue = 0;
subtotalOtherChargeValue = Convert.ToDecimal(dataItem["Average"].Text);
totalTaxesOtherCharge += Convert.ToDecimal(dataItem["AppliedTaxRate"].Text);
orderOtherChargesTotalValue = subtotalOtherChargeValue + totalTaxesOtherCharge;
HyperLink editOtherChargeLink = e.Item.FindControl("EditChargeHyperLink") as HyperLink;
DueAmt = Convert.ToInt32(e.Item.OwnerTableView.ParentItem.GetDataKeyValue("DueAmt"));
Qty = Convert.ToInt32(e.Item.OwnerTableView.ParentItem.GetDataKeyValue("Qty"));
}
}
if (e.Item is GridFooterItem && e.Item.OwnerTableView.DataMember.Equals("items"))
{
GridFooterItem footerItem = e.Item as GridFooterItem;
if (footerItem != null)
{
RadNumericTextBox TotalRadNumericTextBox = footerItem.FindControl("TotalRadNumericTextBox") as RadNumericTextBox;
if (TotalRadNumericTextBox != null)
TotalRadNumericTextBox.Text = Math.Round(_totalSubtotalValue, 3).ToString();
RadNumericTextBox ChargesRadNumericTextBox = footerItem.FindControl("ChargesRadNumericTextBox") as RadNumericTextBox;
if (ChargesRadNumericTextBox != null)
ChargesRadNumericTextBox.Text = Math.Round(_totalChargesValue, 3).ToString();
RadNumericTextBox taxesRadNumericTextBox = footerItem.FindControl("TaxesRadNumericTextBox") as RadNumericTextBox;
if (taxesRadNumericTextBox != null)
taxesRadNumericTextBox.Text = Math.Round(_totalTaxesValue, 3).ToString();
RadNumericTextBox subTotalRadNumericTextBox = footerItem.FindControl("subTotalRadNumericTextBox") as RadNumericTextBox;
if (subTotalRadNumericTextBox != null)
subTotalRadNumericTextBox.Text = Math.Round((RecordTotalValue), 2).ToString();
}
}
}
}
protected void ExpandCollapseAllLinkButton_Click(object sender, EventArgs e)
{
foreach (GridItem item in sampleRadGrid.MasterTableView.Controls[0].Controls)
{
if (ViewState["Expanded"] == null)
item.Expanded = true;
else
item.Expanded = false;
}
if (ViewState["Expanded"] != null)
ViewState["Expanded"] = null;
else
ViewState["Expanded"] = true;
sampleRadGrid.MasterTableView.ShowFooter = true;
}
protected void ExportToExcelImageButton_Click(object sender, EventArgs e)
{
ExportDataToFile();
ExportToExcel(sampleRadGrid, "SampleGridData");
}
protected void ExportToWordImageButton_Click(object sender, EventArgs e)
{
ExportDataToFile();
ExportToWord(sampleRadGrid, "SampleGridData");
}
protected void ExportToCsvImageButton_Click(object sender, EventArgs e)
{
ExportDataToFile();
ExportToCsv(sampleRadGrid, "SampleGridData");
}
private void ExportDataToFile()
{
sampleRadGrid.MasterTableView.ExpandCollapseColumn.Display = false;
sampleRadGrid.MasterTableView.DetailTables[0].ExpandCollapseColumn.Display = false;
sampleRadGrid.MasterTableView.DetailTables[0].CommandItemDisplay = GridCommandItemDisplay.None;
sampleRadGrid.ShowFooter = true;
sampleRadGrid.MasterTableView.DetailTables[0].ShowFooter = true;
}
protected void Page_PreRender(object sender, System.EventArgs e)
{
GridItem commandItem = sampleRadGrid.MasterTableView.GetItems(GridItemType.CommandItem)[0];
ImageButton exportToExcelImageButton = commandItem.FindControl("ExportToExcelImageButton") as ImageButton;
ImageButton exportToWordImageButton = commandItem.FindControl("ExportToWordImageButton") as ImageButton;
ImageButton exportToCsvImageButton = commandItem.FindControl("ExportToCsvImageButton") as ImageButton;
if (sampleRadGrid.Items.Count > 0)
{
if (_isFirstTime)
_isFirstTime = false;
}
ExpandCollapseAllLinkButton.Enabled = sampleRadGrid.MasterTableView.Items.Count > 0;
if (ExpandCollapseAllLinkButton != null)
ExpandCollapseAllLinkButton.Enabled = sampleRadGrid.Items.Count > 0;
OrderDetailDetailMenu.PrintOrderPrintLinkButtonControl.Enabled = sampleRadGrid.Items.Count > 0;
Boolean isGridHasData = sampleRadGrid.Items.Count > 0;
if (exportToExcelImageButton != null)
{
exportToExcelImageButton.Enabled = isGridHasData;
if (exportToExcelImageButton.Enabled)
{
exportToExcelImageButton.Attributes.Add("onclick", String.Format("DisableAjax(\"{0}\", \"\"); return false;", exportToExcelImageButton.UniqueID));
exportToExcelImageButton.Style.Add(StringResources.CssCursorKey, StringResources.CssCursorValue);
}
}
if (exportToWordImageButton != null)
{
exportToWordImageButton.Enabled = isGridHasData;
if (exportToWordImageButton.Enabled)
{
exportToWordImageButton.Attributes.Add("onclick", String.Format("DisableAjax(\"{0}\", \"\"); return false;", exportToWordImageButton.UniqueID));
exportToWordImageButton.Style.Add(StringResources.CssCursorKey, StringResources.CssCursorValue);
}
}
if (exportToCsvImageButton != null)
{
exportToCsvImageButton.Enabled = isGridHasData;
if (exportToCsvImageButton.Enabled)
{
exportToCsvImageButton.Attributes.Add("onclick", String.Format("DisableAjax(\"{0}\", \"\"); return false;", exportToCsvImageButton.UniqueID));
exportToCsvImageButton.Style.Add(StringResources.CssCursorKey, StringResources.CssCursorValue);
}
}
}
private Info GetOrder(Boolean clearCache)
{
if (_requireReload)
{
try
{
String cacheName = String.Format("Order{0}{1}", RecordID, _guid);
if (!clearCache && CacheObject[cacheName] != null)
return (Info)CacheObject[cacheName];
else
{
Info Info = Info.GetInfo(RecordID, true);
AddCache(cacheName, Info);
HiddenLabel.Text = RecordID.ToString();
DetailTitleLabel.Text = String.Format("Order {0}", RecordID);
DetailHeaderLabel.Text = String.Format("Created By {0} {1}", Info.OrderedByFirstName, Info.OrderedByLastName);
return Info;
}
}
catch (Exception ex)
{
}
}
return null;
}
}
protected void AddCustomPager(RadGrid radGrid)
{
radGrid.PageSize = 10;
radGrid.AllowPaging = true;
radGrid.MasterTableView.PagerStyle.AlwaysVisible = true;
foreach (GridTableView gridTableView in radGrid.MasterTableView.DetailTables)
{
gridTableView.PageSize = 10;
gridTableView.AllowPaging = true;
gridTableView.PagerStyle.AlwaysVisible = true;
}
radGrid.ItemCreated += new GridItemEventHandler(RadGrid_ItemCreated);
if (radGrid.ID != "InformationRadGrid")
radGrid.ItemCommand += new GridCommandEventHandler(RadGrid_ItemCommand);
}
protected void ExportToExcel(RadGrid searchRadGrid, String fileName)
{
searchRadGrid.MasterTableView.HierarchyDefaultExpanded = true;
if (searchRadGrid.MasterTableView.HasDetailTables)
{
foreach (GridTableView gridTableView in searchRadGrid.MasterTableView.DetailTables)
{
gridTableView.AllowPaging = false;
gridTableView.HierarchyDefaultExpanded = true;
}
}
searchRadGrid.ExcelExportCellFormatting += new OnExcelExportCellFormattingEventHandler(SearchRadGrid_ExcelExportCellFormatting);
searchRadGrid.ItemCreated += new GridItemEventHandler(RadGrid_ItemCreated);
searchRadGrid.ExportSettings.ExportOnlyData = true;
searchRadGrid.ExportSettings.IgnorePaging = true;
searchRadGrid.ExportSettings.OpenInNewWindow = true;
searchRadGrid.ExportSettings.FileName = fileName;
_isExport = true;
searchRadGrid.MasterTableView.ExportToExcel();
}
protected void ExportToWord(RadGrid searchRadGrid, String fileName)
{
searchRadGrid.MasterTableView.HierarchyDefaultExpanded = true;
if (searchRadGrid.MasterTableView.HasDetailTables)
{
foreach (GridTableView gridTableView in searchRadGrid.MasterTableView.DetailTables)
{
gridTableView.AllowPaging = false;
gridTableView.HierarchyDefaultExpanded = true;
}
}
searchRadGrid.ItemCreated += new GridItemEventHandler(RadGrid_ItemCreated);
searchRadGrid.ExportSettings.ExportOnlyData = true;
searchRadGrid.ExportSettings.IgnorePaging = true;
searchRadGrid.ExportSettings.OpenInNewWindow = true;
searchRadGrid.ExportSettings.FileName = fileName;
_isExport = true;
searchRadGrid.MasterTableView.ExportToWord();
}
protected void ExportToCsv(RadGrid searchRadGrid, String fileName)
{
if (searchRadGrid.MasterTableView.HasDetailTables)
{
foreach (GridTableView gridTableView in searchRadGrid.MasterTableView.DetailTables)
gridTableView.HierarchyDefaultExpanded = true;
}
searchRadGrid.MasterTableView.HierarchyDefaultExpanded = true;
searchRadGrid.GridExporting += new OnGridExportingEventHandler(RadGrid_GridExporting); // Defect - 9405 - 21 Jun 2011 - By Partner CB
searchRadGrid.ItemCreated += new GridItemEventHandler(RadGrid_ItemCreated);
searchRadGrid.ExportSettings.ExportOnlyData = isExportOnlydata;
searchRadGrid.ExportSettings.IgnorePaging = true;
searchRadGrid.ExportSettings.OpenInNewWindow = true;
searchRadGrid.ExportSettings.FileName = fileName;
_isExport = true;
searchRadGrid.MasterTableView.ExportToCSV();
}
Thanks