I have RadGrid which contains GridTableView as rows inside <DetailTables>. One of the column in RadGrid contains the image button. My requirement is whenever the Image Button from the row is clicked i need to export the data from the respective GridTableView in to Excel Sheet. I am able to export the entire grid data in to excel (tatSummaryGrd.MasterTableView.ExportToExcel()) but NOT able to export the row wise data(GridTableView data) in to Excel.
Please find the code below and advise how i can achieve this.
<radG:RadGrid ID="tatSummaryGrd"
runat="server" AllowMultiRowSelection="False" AllowPaging="False"
Width="100%" AllowSorting="True" AutoGenerateColumns="False" BorderColor="LightBlue"
BorderWidth="1px" AllowMultiRowEdit="true" EnableAJAX="True" GridLines="None"
OnDetailTableDataBind="tatSummaryGrd_DetailTableDataBind"
OnNeedDataSource="tatSummaryGrd_NeedDataSource"
OnItemCommand = "tatSummaryGrd_ItemCommand"
Skin="SkeltaGrid" RadControlsDir="<%$ ReplaceTemplateExpn:telerik/radcontrols/%>"
>
<mastertableview nodetailrecordstext="No records found " nomasterrecordstext="No records found"
autogeneratecolumns="false" DataSourceID=""
datakeynames="ImportID" HierarchyDefaultExpanded="false">
<Columns>
<radG:GridTemplateColumn UniqueName="Process" >
<HeaderTemplate>
Process
</HeaderTemplate>
<ItemTemplate>
<label>
<%# Eval("Process")%>
</label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</radG:GridTemplateColumn>
<radG:GridTemplateColumn UniqueName="SubProcess" >
<HeaderTemplate>
Sub Process
</HeaderTemplate>
<ItemTemplate>
<label>
<%# Eval("SubProcess")%>
</label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</radG:GridTemplateColumn>
<radG:GridTemplateColumn UniqueName="ExportToExcel" >
<HeaderTemplate>
Export to Excel
</HeaderTemplate>
<ItemTemplate>
<asp:ImageButton ID="exportToExcelImgBtn" runat="server" CommandName="Excel" ImageUrl="../skimages/msexcel.jpg"
ToolTip="Export to Excel" />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</radG:GridTemplateColumn>
</Columns>
<DetailTables>
<radG:GridTableView Name="Policies" DataKeyNames="ImportID,PolicyID,InternalPolicyID,ExecutionId" AllowMultiColumnSorting="True"
DataSourceID="" TabIndex="0" AllowAutomaticUpdates="true"
>
<ParentTableRelation>
<radG:GridRelationFields MasterKeyField="ImportID" DetailKeyField="ImportID" />
</ParentTableRelation>
<Columns>
<radG:GridTemplateColumn UniqueName="PolicyID">
<HeaderTemplate>
Policy
</HeaderTemplate>
<ItemTemplate>
<label >
<%# Eval("PolicyID")%>
</label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="left" Width="90px" />
<ItemStyle HorizontalAlign="Left" Width="90px" />
</radG:GridTemplateColumn>
<radG:GridTemplateColumn UniqueName="ExistsInExcel">
<HeaderTemplate>
Money Recieved
</HeaderTemplate>
<ItemTemplate>
<%# Eval("ExistsInExcel")%>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="90px" />
<ItemStyle HorizontalAlign="Center" Width="90px" />
</radG:GridTemplateColumn>
</Columns>
</radG:GridTableView>
</DetailTables>
</mastertableview>
<exportsettings exportonlydata="true" filename="Work Item Status Report" ignorepaging="true" openinnewwindow="true">
</exportsettings>
</radG:RadGrid>
Code Behind:
protected
void tatSummaryGrd_NeedDataSource(object source, GridNeedDataSourceEventArgs e) {
tatSummaryGrd.DataSource = InsuranceProcessLib.GetExcelImportHistory(_FromDate, _ToDate);
}
protected void tatSummaryGrd_DetailTableDataBind(object source, Telerik.WebControls.GridDetailTableDataBindEventArgs e) {
if (_DataViews.Contains(e.DetailTableView)) return;
_DataViews.Add(e.DetailTableView);
int importID = BPM.IsNullInt(e.DetailTableView.ParentItem.GetDataKeyValue("ImportID"), 0);
e.DetailTableView.DataSource = InsuranceProcessLib.GetExcelImportPolicyList(importID);
e.DetailTableView.DataBind();
}
protected void tatSummaryGrd_ItemCommand(object source, GridCommandEventArgs e) {
if (e.CommandName == "Excel") {
Int32 index = Convert.ToInt32(e.CommandArgument);
GridDataItem item = tatSummaryGrd.Items[index];
item.OwnerTableView.ExportToExcel();
}
}
}