Telerik Forums
UI for ASP.NET AJAX Forum
2 answers
921 views
I want to be able to Export to Excel from a RadGrid. The RadGrids on various pages could have 1 detail table or multiple nested detail tables (detail tables inside detail tables.)

I want the user to be able to expand one or more records to view the detail tables and if they export to excel, export it exactly as they see it with paging ignored. There may be multiple expanded detail tables on the same level, or nested tables may be expanded.

Here's the HTML and VB.NET code behind of a fully independent sample page of how our grids are implemented. This has a fake datasource hard coded, we're using LINQ queries to a SQL database in the real website.

This was made in Visual Studio 2012.

Thanks for any help you can offer. We haven't found any help online that has worked.






<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="DetailTableExportSample.WebForm1" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
 
<!DOCTYPE html>
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <b>Thanks for helping!</b><br />
        What we want is for one or more of the records in the master (top level) RadGrid to be expanded to display the detail table and then that view, exactly as you see it, to be exportable to Excel.
        <br /><br />
        Below is a simplified example to illustrate our setup. The solution will also need to work if there are multiple detail tables nested (meaning the detail table has it's own detail table).
        <br /><br />
        Please post a response in the forum thread.
 
    </div>
        <br /><br />
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
 
        <telerik:RadGrid AllowSorting="true" ID="rgPeople" runat="server" AutoGenerateColumns="False" Width="500px" CellSpacing="0" GridLines="None">
            <GroupingSettings CaseSensitive="false" />
            <ExportSettings FileName="PM Export" IgnorePaging="true" HideStructureColumns="true" OpenInNewWindow="true" Excel-Format="Html" ExportOnlyData="true" />
            <MasterTableView PageSize="25" DataKeyNames="LName" CommandItemDisplay="Top" AllowPaging="true" AllowSorting="true">
                  <DetailTables>
                       <telerik:GridTableView DataKeyNames="courseID" Name="rgDetail" Width="100%" AllowFilteringByColumn="false">
                           <Columns>
                               <telerik:GridBoundColumn DataField="courseID" HeaderText="Course ID" />
                               <telerik:GridBoundColumn DataField="name" HeaderText="Course" />
                               <telerik:GridBoundColumn DataField="classroom" HeaderText="Room" />
                           </Columns>
                       </telerik:GridTableView>
                  </DetailTables>
                <EditFormSettings EditColumn-InsertText="Add" EditColumn-ButtonType="ImageButton" />
                <CommandItemSettings ShowAddNewRecordButton="false" ShowExportToExcelButton="true" />
                <Columns>
                    <telerik:GridBoundColumn DataField="FName" HeaderText="First" />
                    <telerik:GridBoundColumn DataField="LName" HeaderText="Last" />
                    <telerik:GridBoundColumn DataField="Gender" HeaderText="Gender" />
                </Columns>
                <PagerStyle AlwaysVisible="true" PageSizeControlType="RadComboBox" PageSizes="25,50,100,200,500" />
            </MasterTableView>
        </telerik:RadGrid>
    </form>
</body>
</html>

Imports Telerik.Web.UI
 
Public Class WebForm1
    Inherits System.Web.UI.Page
    Property people As List(Of person)
        Get
            Return ViewState("_people")
        End Get
        Set(value As List(Of person))
            ViewState("_people") = value
        End Set
    End Property
    Property classes As List(Of course)
        Get
            Return ViewState("_classes")
        End Get
        Set(value As List(Of course))
            ViewState("_classes") = value
        End Set
    End Property
 
    Property attendees As List(Of enrollment)
        Get
            Return ViewState("_attendees")
        End Get
        Set(value As List(Of enrollment))
            ViewState("_attendees") = value
        End Set
    End Property
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            MakePeopleList()
            MakeClassesList()
            MakeAttendeesList()
 
            rgPeople.Rebind()
        End If
    End Sub
 
    Private Sub rgPeople_DetailTableDataBind(sender As Object, e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles rgPeople.DetailTableDataBind
        Dim dataItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
        Select Case e.DetailTableView.Name
            Case "rgDetail"
                Dim student As String = dataItem.GetDataKeyValue("LName").ToString
                e.DetailTableView.DataSource = From a In attendees
                                               Join c In classes On c.courseID Equals a.courseID
                                               Where a.student_LName = student
                                               Select c
 
        End Select
    End Sub
 
    Private Sub rgPeople_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgPeople.NeedDataSource
        'our actual datasource is a LINQ-SQL query
        If people.Count = 0 Then
            rgPeople.DataSource = Nothing
        Else
            rgPeople.DataSource = From p In people
        End If
    End Sub
 
 
 
#Region "Make_Fake_DataSources"
    Sub MakePeopleList()
        Dim p As New List(Of person)
 
        'people = New List(Of person)
        p.Add(New person("Gary", "Ritter", "Male"))
        p.Add(New person("Bill", "Becker", "Male"))
        p.Add(New person("Michael", "McClary", "Male"))
        p.Add(New person("Angela", "Paulone", "Female"))
        p.Add(New person("Alison", "Weichert", "Female"))
 
        people = p
 
    End Sub
 
    Sub MakeClassesList()
        Dim c As New List(Of course)
        c.Add(New course("HIS101", "American History", "H13"))
        c.Add(New course("ENG101", "English - Freshman", "E10"))
        c.Add(New course("PHY101", "Physical Education", "GYM"))
        c.Add(New course("MTH201", "Algebra 2", "M04"))
        c.Add(New course("SCI106", "Computer Basics", "L03"))
        c.Add(New course("SCI110", "AFJROTC", "S10"))
        classes = c
 
    End Sub
 
    Sub MakeAttendeesList()
        Dim a As New List(Of enrollment)
        a.Add(New enrollment("Ritter", "MTH201"))
        a.Add(New enrollment("Ritter", "SCI110"))
        a.Add(New enrollment("Ritter", "PHY101"))
 
        a.Add(New enrollment("Becker", "SCI106"))
        a.Add(New enrollment("Becker", "HIS101"))
 
        a.Add(New enrollment("McClary", "HIS101"))
        a.Add(New enrollment("McClary", "SCI106"))
        a.Add(New enrollment("McClary", "ENG101"))
 
        a.Add(New enrollment("Paulone", "HIS101"))
        a.Add(New enrollment("Paulone", "PHY101"))
        a.Add(New enrollment("Paulone", "SCI110"))
 
        a.Add(New enrollment("Weichert", "PHY101"))
        a.Add(New enrollment("Weichert", "ENG101"))
        a.Add(New enrollment("Weichert", "MTH201"))
 
        attendees = a
    End Sub
#End Region
End Class
 
 
#Region "Datasource_Classes"
<Serializable>
Public Class person
    Public Property FName As String
    Public Property LName As String
    Public Property Gender As String
 
    Public Sub New(First_Name As String, Last_Name As String, my_Gender As String)
        Me.FName = First_Name
        Me.LName = Last_Name
        Me.Gender = my_Gender
    End Sub
 
    Public Sub New()
    End Sub
End Class
 
<Serializable>
Public Class course
    Public Property courseID As String
    Public Property name As String
    Public Property classroom As String
 
    Public Sub New(id As String, course_name As String, classroom_number As String)
        Me.courseID = id
        Me.name = course_name
        Me.classroom = classroom_number
    End Sub
 
    Public Sub New()
    End Sub
End Class
 
<Serializable>
Public Class enrollment
    Public Property student_LName As String
    Public Property courseID As String
 
    Public Sub New(Last_Name As String, id As String)
        Me.student_LName = Last_Name
        Me.courseID = id
    End Sub
 
    Public Sub New()
    End Sub
End Class
#End Region
David
Top achievements
Rank 1
 answered on 13 Oct 2014
1 answer
111 views
I have a tab strip with scrolling enabled.  When I select a tab, a postback occurs, and then the tab strip always scrolls back to the top, leaving our users no way to know which tab they've selected unless they scroll back.  Has anyone else experienced this?  I've tried setting the ScrollPosition during the postback, but it had no effect.  I've tried this with PerTabScrolling set to both true and false.  Any ideas?
Matt DiPietro
Top achievements
Rank 1
 answered on 13 Oct 2014
1 answer
306 views
01.<telerik:RadGrid ID="RadGrid1"  runat="server">       
02.    <MasterTableView DataKeyNames="EntityID" AutoGenerateColumns="false" ShowHeader="false" ShowFooter="false">
03.        <Columns>
04.            <telerik:GridTemplateColumn UniqueName="EntitySelector">
05.                <ItemTemplate>
06.                    <div  class="item">
07.                        <label class="name"><%# ((Domain.Entities.Model)Container.DataItem).ModelName%></label>
08.                        <label class="abbr"><%# ((Domain.Entities.Model)Container.DataItem).ModelTypeName %></label>
09.                        <img class="type" src="media/<%# ((Domain.Entities.Model)Container.DataItem).ModelTypeImageURI %>" alt="<%# ((Domain.Entities.Model)Container.DataItem).ModelTypeName %>" />
10.                        <telerik:RadButton ID="btnSelectModel" runat="server" OnClick="btnSelectModel_Click" Value="<%# ((Domain.Entities.Model)Container.DataItem).EntityID %>" Text="Select Entity"></telerik:RadButton>
11.                    </div>
12.                </ItemTemplate>
13.            </telerik:GridTemplateColumn>
14.        </Columns>
15.    </MasterTableView>                           
16.</telerik:RadGrid>


This preceeding code functions, what I want is to have the content template of the RadButton contain the div [class=item] section, so that I can make the entire gridItem clickable (handled server-side).. when I attempt to do that, I get a design time error regarding Telerik.Web.UI.RibbonBarTemplateItem (Container) not containing DataItem. 

I'm really just looking for a clickable container here to wrap my content.. it doesn't have to be the RadButton

Brett
Top achievements
Rank 1
 answered on 13 Oct 2014
4 answers
152 views
I tried enabling the scrolling feature for a grid. This works perfectly if the grid isn't contained in a <table> tag.... But if the grid is inside a table, Weird things happen....

If you use IE7, and you resize the IE7 window, IE freezes..
If you use Firefox 2 or Safari, about 2% of the grid will show up.. Resizing it will only show 1 column for Firefox2...

Is there anyone out there experiencing these behaviours? Anyone got a solution?

Thanks.
Joel R
Top achievements
Rank 1
 answered on 13 Oct 2014
2 answers
234 views
Having trouble getting RadBarcodes to scan unless made larger than default with LineWidth = 2.  UPC-A and EAN are the troublemakers with LineWidth = 1.  ITF-14 scans ok at LineWidth = 1. 

As documentation suggests, we tried setting Height and Width to empty strings to let control size things as it needs based on LineWidth setting.  Also tried using code like Height = New Unit(1.02, UnitType.inch) and Width = New Unit(1.469, UnitType.inch) to set to standard UPCA 1.02in x 1.469in size, but the RadBarcode control seems to just ignore the settings.  Any clues as to why LineWidth = 1 won't scan?   I can't find any other RadBarcode control properties that would help.

When I check the industry standard on UPCA, it says that the size is allowed to be anywhere from 80% to 200% of 1.02in x 1.469in.  But I can't find any way to make the RadBarcode create it in anything but mutliple of LineWidth (i.e. LineWidth=1 is default size, LineWidth=2 is twice as large, ...etc).

Its not a problem with our scanner, which is able to scan other smaller UPCA and ITF14 barcodes (not generated from RadBarcode) without problem. We are using a pretty standard Motorola LS2208 handheld scanner for testing, which is what our vendors are using.

Declaring control as
<telerik:RadBarcode runat="server" ID="cuBarCode" Width="" Height="" ></telerik:RadBarcode>

Setting up in codebehind as follows since we have to support 4 different barcodes types based on user choice...
Public Sub SetRadbarcodeProperties(ByVal barcodeCtl As RadBarcode, ByVal bc As FPHBarCode)
 
    barcodeCtl.OutputType = BarcodeOutputType.EmbeddedPNG
    barcodeCtl.Text = bc.Value
 
    Select Case bc.Type
        Case "ITF-14"
            barcodeCtl.Type = BarcodeType.Code25Interleaved
            barcodeCtl.RenderChecksum = False
            barcodeCtl.LineWidth = 2
        Case "UPC-A"
            barcodeCtl.Type = BarcodeType.UPCA
            barcodeCtl.RenderChecksum = True
            barcodeCtl.LineWidth = 2
        Case "EAN-13"
            barcodeCtl.Type = BarcodeType.EAN13
            barcodeCtl.RenderChecksum = True
            barcodeCtl.LineWidth = 2
        Case "UPC-E"
            barcodeCtl.Type = BarcodeType.UPCE
            barcodeCtl.RenderChecksum = True
            barcodeCtl.LineWidth = 2
        Case Else
            Throw New InvalidOperationException("Cannot handle barcode type=" + bc.Type)
    End Select
 
End Sub
John
Top achievements
Rank 1
 answered on 13 Oct 2014
1 answer
397 views
Hi Telerik,

I have a problem where I set all 'input' to call a javascript function from my $(document).ready (as you can see below). The problem is that:

$(':input, textarea, select').not(".rgFilterBox, .RadGrid, .rgPagerTextBox").change

is not fired when I go to my comoboBox and select a different index. ( code for radbox below). Yes I have a "OnClientSelectedIndexChanged"
on the control, but I don't want to use that property in this case. I want to use the one from $(document).ready. 

Is there a way to pick up the selected index change from $(document).ready? 

------------------------------------------code here --------------------------------------------
$(document).ready(function () {

    $(':input, textarea, select').not(".rgFilterBox, .RadGrid, .rgPagerTextBox").change(function () {
        setIsDirtyFlag();
    });

});

<telerik:RadComboBox ID="RadComboBoxClearance" runat="server" TabIndex="9" MaxHeight="100" OnClientSelectedIndexChanged="setIsDirtySARFlag"
 Width="215px" EmptyMessage="Select..." MarkFirstMatch="true" Filter="StartsWith"
 RenderMode="Auto">
</telerik:RadComboBox>


Boyan Dimitrov
Telerik team
 answered on 13 Oct 2014
1 answer
233 views
I have a stored procedure which returns multiple result sets. The code calls the procedure with ExecuteReader(CommandBehavior.CloseConnection), and then proceeds to fill several grids, as follows:

thisgrid.DataSource = dr
thisgrid.DataBind()
dr.NextResult()
thatgrid.DataSource = dr
thatgrid.DataBind()
dr.NextResult()
theothergrid.DataSource = dr
theothergrid.DataBind()
dr.NextResult()

Up until now, we've been using Infragistics grids. But now we're converting to Telerik, and I'm running into a problem. After the first grid is bound, the DataReader closes, and the call to NextResult() results in a "reader is closed" error.

So, my first question is, how do I tell the DataBind method, "Hey, don't close that connection - there are more result sets coming"?

I know that if I remove CommandBehavior.CloseConnection from the ExecuteReader command, the DataReader stays open, but then I'm left with an open connection. So my second question is, how do insure that the connection gets closed? Is it automatically closed when the DataReader closes?
Konstantin Dikov
Telerik team
 answered on 13 Oct 2014
1 answer
144 views
Hello,

I searched a while but didn't find an appropriate Example.

I have a RadGridView bound to a EntityDataSource (EF 6). Everthing works fine (Sorting, Filtering), but now I ran into some Gotchas:

I have a primary key column ( = Entity Property) that is not shown in the grid, but I want to set a default filter on that column. When I try to use the where-property (AutoGenerateWhereClause = true) of the EntityDataSource I run into conflicts with the standard grid column filters. Which is the best way to achieve that?

I neet to fill additional column values when inserting new items, especially the primary keys. How should i do this?

Greetings Jochen
Marin
Telerik team
 answered on 13 Oct 2014
1 answer
96 views
Hi,

what ist the best practice to bind the CheckboxColumn to a non boolean column / property (we have a legacy database that uses smallint instead - like null or 0 for false and 1 for true)? I tried it with a partial class with wrapper properties on entity Level, but then ran into errors when inserting / updateing / editing within RadGrid


Exception = {"A property named 'BSPERRUNG' was not found on the entity during an insert, update, or delete operation. Check to ensure that properties specified as binding expressions are available to the data source."}

BSPERRUNG is the wrapper property for SPERRUNG, that is the original smallint column.

Are there any possibilities to achieve this with built in RadGridView features?

Greets Jochen
Marin
Telerik team
 answered on 13 Oct 2014
2 answers
76 views
HI,

I try to get the 'Standalone Tiles' example from your demo Website ( http://demos.telerik.com/aspnet-ajax/tilelist/examples/standalonetiles/defaultcs.aspx )
to run on my System.

In the mentioned example you have the following JavaScript code:

function liveTileOnClientTemplateDataBound(sender, args) {            var index = args.get_dataItem().index + 1;            if (index > 2) {                index = 0;            }            sender.set_value(index.toString());        }

Inside the code you use a function with Name set_value().
I assume what this function should do is to set the 'Value' property of the live tile.
Unfortunately there is no place in the online doc to a 'set_value()' function, at least I did not find it. Also no mentioning in the Forum.

What I THOUGHT I can do with this function is to set the value of the 'context' object Parameter to Server side pagemethod specified in the WebServiceSettings tag of the live tile.

But to what ever I set the value in set_value() it has no influence to the context object in the pagemethod.

Since set_value is not documented- Is this function really doing something or is the code in the demo wrong ?

I really WOULD like to set the value of the context object of the pagemethod.
How can I do this (if set_value is NOT the way to do it) ????

Hope that someone knows an answer.
Best regards
Hans-Juergen















 
Marin Bratanov
Telerik team
 answered on 13 Oct 2014
Narrow your results
Selected tags
Tags
+? more
Top users last month
Jay
Top achievements
Rank 3
Iron
Iron
Iron
Benjamin
Top achievements
Rank 3
Bronze
Iron
Veteran
Radek
Top achievements
Rank 2
Iron
Iron
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Richard
Top achievements
Rank 4
Bronze
Bronze
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jay
Top achievements
Rank 3
Iron
Iron
Iron
Benjamin
Top achievements
Rank 3
Bronze
Iron
Veteran
Radek
Top achievements
Rank 2
Iron
Iron
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Richard
Top achievements
Rank 4
Bronze
Bronze
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?