Trying to export my sub grid as well but it seems to not work, following the instructions found on teleriks sites but to no avail.
Mu grid is wrapped in update panel and it works to export the main grid just fine just no sub grids come along. Here is the code I put in to take care of the issue but nothing. I am using all the radgrid advanced data binding methods.
Mu grid is wrapped in update panel and it works to export the main grid just fine just no sub grids come along. Here is the code I put in to take care of the issue but nothing. I am using all the radgrid advanced data binding methods.
<CommandItemTemplate> <asp:Button ID="btnExport" runat="server" CommandName="ExportToExcel" Text="Export Excel" /></CommandItemTemplate> Protected Sub myRadGrid_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles myRadGrid.ItemCommand If e.CommandName = "ExportToExcel" Then For Each item As GridItem In myRadGrid.MasterTableView.Items item.Expanded = True Next isExport = True End If End Sub Protected Sub myRadGrid_ItemCreated(sender As Object, e As GridItemEventArgs) Handles myRadGrid.ItemCreated If Not isExport Then If TypeOf e.Item Is GridCommandItem Then ScriptManager.GetCurrent(Page).RegisterPostBackControl(e.Item.FindControl("btnExport")) End If End If End Sub4 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 04 Jan 2014, 05:20 AM
Hi Kevin,
Below is a sample code snippet that i tried which works fine at my end, can you please give a try and check what is the difference with yours.
ASPX:
VB:
JS:
Thanks,
Princy
Below is a sample code snippet that i tried which works fine at my end, can you please give a try and check what is the difference with yours.
ASPX:
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="onRequestStart"> <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" AllowPaging="True" OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand"> <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true"> </ExportSettings> <MasterTableView DataKeyNames="OrderID" Name="Parent" HierarchyLoadMode="Client" CommandItemDisplay="Top"> <CommandItemTemplate> <asp:Button ID="btnExport" runat="server" CommandName="ExportToExcel" Text="Export Excel" /> </CommandItemTemplate> <DetailTables> <telerik:GridTableView AutoGenerateColumns="false" DataKeyNames="OrderID" Name="Orders" CommandItemDisplay="Bottom"> <Columns> <telerik:GridBoundColumn SortExpression="UnitPrice" HeaderText="Unit Price" HeaderButtonType="TextButton" DataField="UnitPrice"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Quantity" HeaderText="Quantity" HeaderButtonType="TextButton" DataField="Quantity"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Discount" HeaderText="Discount" HeaderButtonType="TextButton" DataField="Discount"> </telerik:GridBoundColumn> </Columns> </telerik:GridTableView> </DetailTables> <Columns> <telerik:GridBoundColumn SortExpression="OrderID" HeaderText="OrderID" HeaderButtonType="TextButton" DataField="OrderID" ReadOnly="true"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="OrderDate" HeaderText="Date Ordered" HeaderButtonType="TextButton" DataField="OrderDate" UniqueName="OrderDate" DataFormatString="{0:D}"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Freight" HeaderText="Freight" HeaderButtonType="TextButton" DataField="Freight" UniqueName="Freight"> </telerik:GridBoundColumn> </Columns> </MasterTableView> <ClientSettings AllowExpandCollapse="true"> </ClientSettings> </telerik:RadGrid></telerik:RadAjaxPanel>VB:
Protected Sub RadGrid1_NeedDataSource(source As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) If Not e.IsFromDetailTable Then RadGrid1.DataSource = GetDataTable("SELECT * FROM Orders") End IfEnd SubProtected Sub RadGrid1_DetailTableDataBind(source As Object, e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Dim dataItem As GridDataItem = DirectCast(e.DetailTableView.ParentItem, GridDataItem) Select Case e.DetailTableView.Name Case "Orders" If True Then Dim OrderID As String = dataItem.GetDataKeyValue("OrderID").ToString() e.DetailTableView.DataSource = GetDataTable((Convert.ToString("SELECT * FROM [Order Details] WHERE OrderID = '") & OrderID) + "'") Exit Select End If End SelectEnd SubPublic Function GetDataTable(query As String) As DataTable Dim ConnString As [String] = ConfigurationManager.ConnectionStrings("Northwind_newConnectionString3").ConnectionString Dim conn As New SqlConnection(ConnString) Dim adapter As New SqlDataAdapter() adapter.SelectCommand = New SqlCommand(query, conn) Dim myDataTable As New DataTable() conn.Open() Try adapter.Fill(myDataTable) Finally conn.Close() End Try Return myDataTableEnd FunctionProtected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs) If e.CommandName = "ExportToExcel" Then For Each item As GridItem In RadGrid1.MasterTableView.Items item.Expanded = True Next End IfEnd SubJS:
<script type="text/javascript"> function onRequestStart(sender, args) { if (args.get_eventTarget().indexOf("btnExport") >= 0) { args.set_enableAjax(false); } }</script>Thanks,
Princy
0
Kevin
Top achievements
Rank 1
answered on 07 Jan 2014, 05:47 PM
Hi Princy,
Calling no joy on this one, I put inot the code things I thought where missing from your side but it still does not expand the grid on export. When I do this no expansion of the grid happens.
Calling no joy on this one, I put inot the code things I thought where missing from your side but it still does not expand the grid on export. When I do this no expansion of the grid happens.
<asp:Panel ID="pnlGrid" runat="server" CssClass="CenterGrids"> <telerik:RadGrid ID="myRadGrid" runat="server" Width="70%" Skin="Web20" AllowSorting="true" CssClass="CenterGrids"> <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true"></ExportSettings> <MasterTableView AutoGenerateColumns="false" Font-Size="10" CommandItemDisplay="Top" DataKeyNames="intLocationId" ExpandCollapseColumn-ButtonType="ImageButton" HierarchyLoadMode="Client" ExpandCollapseColumn-CollapseImageUrl="~/Images/30.png" ExpandCollapseColumn-ExpandImageUrl="~/Images/29.png"> <CommandItemStyle HorizontalAlign="Right" Height="30px" /> <CommandItemTemplate> <asp:Button ID="btnExport" runat="server" CommandName="ExportToExcel" Text="Export Excel" /> </CommandItemTemplate> <HeaderStyle Font-Bold="true" HorizontalAlign="Center" /> <ItemStyle HorizontalAlign="Center" /> <AlternatingItemStyle BackColor="#B0C4DE" HorizontalAlign="Center" /> <ParentTableRelation> <telerik:GridRelationFields DetailKeyField="intLocationId" MasterKeyField="intLocationId" /> </ParentTableRelation> <DetailTables> <telerik:GridTableView Name="myManufacGrid" Width="50%" runat="server" DataKeyNames="intLocationId" TableLayout="Fixed" Font-Size="10" AutoGenerateColumns="False" HeaderStyle-HorizontalAlign="Center" > <HeaderStyle Font-Bold="true" HorizontalAlign="Center" /> <AlternatingItemStyle BackColor="#B0C4DE" HorizontalAlign="Center" /> <ItemStyle HorizontalAlign="Center" /> <Columns> <telerik:GridBoundColumn DataField="Name" HeaderText="NAME" /> <telerik:GridBoundColumn DataField="dtsigned" HeaderText="SIGNED" /> </Columns> </telerik:GridTableView> </DetailTables> <Columns> <telerik:GridBoundColumn DataField="strlocationId" HeaderText="LOC ID" /> <telerik:GridBoundColumn DataField="strLocation" HeaderText="LOCATION" /> <telerik:GridBoundColumn DataField="Name" HeaderText="NAME" /> <telerik:GridBoundColumn DataField="dtsigned" HeaderText="LAST SIGNED" /> </Columns> </MasterTableView> <ClientSettings AllowExpandCollapse="true"></ClientSettings> </telerik:RadGrid> </asp:Panel>Protected Sub myRadGrid_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles myRadGrid.ItemCommand If e.CommandName = "ExportToExcel" Then For Each item As GridItem In myRadGrid.MasterTableView.Items item.Expanded = True Next isExport = True End If End Sub Protected Sub myRadGrid_DetailTableDataBind(sender As Object, e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles myRadGrid.DetailTableDataBind sql = "Select ah.intLocationId, ah.dtsigned, ah.strSignature, mn.strFullname + ' ' + strRank Name from tblAnnualHRHist ah INNER JOIN MNNGPersonnel..tblMNNatPersonnel mn on mn.intPersonnelId = ah.intIssuedTo " _ & "where intLocationId = " & e.DetailTableView.ParentItem.GetDataKeyValue("intLocationId") & "order by dtSigned" e.DetailTableView.DataSource = getData(sql) End Sub Protected Sub myRadGrid_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles myRadGrid.NeedDataSource sql = "Select intLocationId, strLocationId, strLocation, Name, dtSigned from vw_LastSigned" myRadGrid.DataSource = getData(sql) End Sub Protected Sub myRadGrid_ItemCreated(sender As Object, e As GridItemEventArgs) Handles myRadGrid.ItemCreated If Not isExport Then If TypeOf e.Item Is GridCommandItem Then ScriptManager.GetCurrent(Page).RegisterPostBackControl(e.Item.FindControl("btnExport")) End If End If End Sub0
Accepted
Princy
Top achievements
Rank 2
answered on 08 Jan 2014, 04:27 AM
Hi Kevin,
Your code works fine at my end. Please try setting the HierarchyDefaultExpanded property of the MasterTableView to true on Export as follows:
VB:
Thanks,
Princy
Your code works fine at my end. Please try setting the HierarchyDefaultExpanded property of the MasterTableView to true on Export as follows:
VB:
Protected Sub myRadGrid_ItemCommand(sender As Object, e As GridCommandEventArgs) If e.CommandName = "ExportToExcel" Then myRadGrid.MasterTableView.HierarchyDefaultExpanded = True isExport = True End IfEnd SubThanks,
Princy
0
Kevin
Top achievements
Rank 1
answered on 08 Jan 2014, 01:34 PM
Hi Princy,
Ok that worked fine, thank you for the help. Telerik Rocks.
Ok that worked fine, thank you for the help. Telerik Rocks.