This is a migrated thread and some comments may be shown as answers.

radgrid created using GridBoundColumn unable to export data into excel and filter

3 Answers 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Abhishek
Top achievements
Rank 1
Abhishek asked on 14 Apr 2011, 03:48 PM
Hi Team,
I have converted my gridview into radgrid. It has GridBoundColumn craeted dynamicaly . Grid is getting populated with data, but 
advance features like filtering ,export to excel are not working. Please assist.

A quick response is highly appreciated !!

Here I am writing code in code block for your reference.

Thanks,
<telerik:RadGrid ID="grvResponses" AllowFilteringByColumn="true" Height="300px" Width="95%"
                            AutoGenerateColumns="False" runat="server">
                            <ExportSettings IgnorePaging="true" OpenInNewWindow="true" ExportOnlyData="true">
                            </ExportSettings>
                            <GroupingSettings CaseSensitive="false" />
                            <ClientSettings AllowColumnsReorder="true" ReorderColumnsOnClient="true" ColumnsReorderMethod="Reorder"
                            AllowGroupExpandCollapse="True" AllowDragToGroup="true">
                            <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True">
                            </Scrolling>
                            <Animation AllowColumnReorderAnimation="true" AllowColumnRevertAnimation="true" ColumnReorderAnimationDuration="100"
                                ColumnRevertAnimationDuration="100" />
                            <ClientEvents />
                        </ClientSettings>
                            <MasterTableView NoMasterRecordsText="No Objects Found !" CommandItemDisplay="Top">
                                <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="false"
                                    ShowExportToCsvButton="false" ShowRefreshButton="false" />
                            </MasterTableView>
                            <ClientSettings AllowDragToGroup="true" AllowColumnsReorder="true" ReorderColumnsOnClient="true"
                                ColumnsReorderMethod="Reorder">                               
                                <Resizing AllowColumnResize="true" AllowResizeToFit="true" />
                                <Animation AllowColumnReorderAnimation="true" AllowColumnRevertAnimation="true" />
                                <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True">
                                </Scrolling>
                            </ClientSettings>
                        </telerik:RadGrid>
 
 
 
 
 
 
  Private Sub BindData()
 
        Dim ReportTypeId As Integer
        Dim ReportDataSourceId As Integer
        Dim rf As DataSourceFactory
        Dim ds As DataSource
        Dim ReportType As New ReportType()
        Dim _displayStyle As String = "S"
        If (SecurityContext.ProjectId = 9) Then
            _displayStyle = "C"
        End If
        Dim dt As Data.DataTable
 
        Dim xMid, xMid1, XAxisLowerLimit, YAxisLowerLimit As String
        Dim yMid, yMid1 As String
        Dim RegionIndex As String
        Dim objDataSourceModel As New DataSourceModel
        Dim AxisX, AxisY, AxisZ As String
        Dim condition As String = ""
        Dim objReportDataSource As New DataSourceType
        Dim has2midval, haszAxis As Boolean
        XAxisLowerLimit = "0"
        YAxisLowerLimit = "0"
 
        ReportDataSourceId = CType(Request.QueryString("ReportDataSourceId"), Integer)
        ReportTypeId = CType(Request.QueryString("ReportTypeId"), Integer)
 
 
        xMid = CType(Request.QueryString("xMid"), String)
        yMid = CType(Request.QueryString("yMid"), String)
        If Not (CType(Request.QueryString("xMid1"), String) Is Nothing) Then
            xMid1 = CType(Request.QueryString("xMid1"), String)
            has2midval = True
        End If
        If Not (CType(Request.QueryString("yMid1"), String) Is Nothing) Then
            yMid1 = CType(Request.QueryString("yMid1"), String)
            has2midval = True
        End If
        RegionIndex = CType(Request.QueryString("RegionIndex"), String)
        XAxis = CType(Request.QueryString("XAxis"), String)
        YAxis = CType(Request.QueryString("YAxis"), String)
        If Not (CType(Request.QueryString("ZAxis"), String) Is Nothing) Then
            ZAxis = CType(Request.QueryString("ZAxis"), String)
            haszAxis = True
        End If
        If Not (CType(Request.QueryString("zAxisLabel"), String) Is Nothing) Then
            ZAxisLabel = CType(Request.QueryString("zAxisLabel"), String)
            haszAxis = True
        End If
        XAxisLabel = CType(Request.QueryString("xAxisLabel"), String)
        YAxisLabel = CType(Request.QueryString("yAxisLabel"), String)
 
        ReportType = CType(ReportTypeId, ReportType)
        rf = New DataSourceFactory()
        ds = rf.CreateDataSource(DataSourceType.PrizmDataSource)
        If (SecurityContext.ProjectId = 0) Then
            Dim f As Field
            f = New Field()
            f.FieldId = "pinProjectId"
            f.FieldType = SqlDbType.Int
            'f.Value = SecurityContext.PId
            'Added By Shankar Pandit
            Dim dtReportProperty As System.Data.DataTable = Nothing
            Dim objReportMaster As APOBL.ReportMaster = New APOBL.ReportMaster()
            dtReportProperty = objReportMaster.getReportProjIDForBucket(ReportId)
            f.Value = dtReportProperty.Rows(0)(0).ToString()
            'End
            objFilter.Fields.Add(f)
 
            f = New Field()
            f.FieldId = "pinReportId"
            f.FieldType = SqlDbType.Int
            f.Value = ReportId.ToString()
            objFilter.Fields.Add(f)
 
            'f = New Field()
            'f.FieldId = "totalRows"
            'f.FieldType = Data.SqlDbType.Int
            'f.Value = "0"
            'f.OutParam = True
            'objFilter.Fields.Add(f)
            'ds.CreateDataSource(objFilter)
            'dt = ds.ProcessedDataSource
        Else
            If (ReportId <> 0) Then
                Dim f As Field
                f = New Field()
                f.FieldId = "pinProjectId"
                f.FieldType = SqlDbType.Int
                f.Value = SecurityContext.ProjectId
                objFilter.Fields.Add(f)
 
                f = New Field()
                f.FieldId = "pinReportId"
                f.FieldType = SqlDbType.Int
                f.Value = ReportId.ToString()
                objFilter.Fields.Add(f)
 
                Session("Filter") = objFilter
                'f = New Field()
                'f.FieldId = "totalRows"
                'f.FieldType = Data.SqlDbType.Int
                'f.Value = "0"
                'f.OutParam = True
                'objFilter.Fields.Add(f)
            Else
                If Not Session("Filter") Is Nothing Then
                    objFilter = Session("Filter")
                End If
            End If
            'ds.CreateDataSource(objFilter)
            'dt = ds.ProcessedDataSource
 
        End If
        ds.CreateDataSource(objFilter)
        dt = ds.ProcessedDataSource
        Cache("data") = dt
        AxisX = XAxis
        AxisY = YAxis
        XAxis = "[" & XAxis & "]"
        YAxis = "[" & YAxis & "]"
 
        If Not has2midval Then
            If RegionIndex = "1" Then
                condition = XAxis + " > " + xMid.ToString() + " And " + YAxis + "<= " + yMid.ToString()
            End If
            If RegionIndex = "0" Then
                condition = XAxis + " <= " + xMid.ToString() + " And " + YAxis + "<= " + yMid.ToString()
            End If
            If RegionIndex = "2" Then
                condition = XAxis + " <= " + xMid.ToString() + " And " + YAxis + "> " + yMid.ToString()
            End If
            If RegionIndex = "3" Then
                condition = XAxis + " > " + xMid.ToString() + " And " + YAxis + ">" + yMid.ToString()
            End If
        Else
            If RegionIndex = "1" Then
                condition = XAxis + " > " + xMid.ToString() + " And " + XAxis + "<= " + xMid1.ToString() + " And " + YAxis + "<= " + yMid.ToString()
            End If
            If RegionIndex = "0" Then
                condition = XAxis + " <= " + xMid.ToString() + " And " + YAxis + "<= " + yMid.ToString()
            End If
            If RegionIndex = "2" Then
                condition = XAxis + " > " + xMid1.ToString() + " And " + YAxis + "<= " + yMid.ToString()
            End If
 
            If RegionIndex = "4" Then
                condition = XAxis + " > " + xMid.ToString() + " And " + XAxis + "<= " + xMid1.ToString() + " And " + YAxis + "<= " + yMid1.ToString() + " And " + YAxis + "> " + yMid.ToString()
            End If
            If RegionIndex = "3" Then
                condition = XAxis + " <= " + xMid.ToString() + " And " + YAxis + "<= " + yMid1.ToString() + " And " + YAxis + "> " + yMid.ToString()
            End If
            If RegionIndex = "5" Then
                condition = XAxis + " > " + xMid1.ToString() + " And " + YAxis + "<= " + yMid1.ToString() + " And " + YAxis + "> " + yMid.ToString()
            End If
 
            If RegionIndex = "7" Then
                condition = XAxis + " > " + xMid.ToString() + " And " + XAxis + "<= " + xMid1.ToString() + " And " + YAxis + "> " + yMid1.ToString()
            End If
            If RegionIndex = "6" Then
                condition = XAxis + " <= " + xMid.ToString() + " And " + YAxis + "> " + yMid1.ToString()
            End If
            If RegionIndex = "8" Then
                condition = XAxis + " > " + xMid1.ToString() + " And " + YAxis + "> " + yMid1.ToString()
            End If
        End If
        Dim newDs As New DataSet()
        dt.DefaultView.RowFilter = condition
 
        grvResponses.DataSource = dt.DefaultView
        
        If _displayStyle = "S" Then
            lblHeader.InnerText = "Objects"
            '   grvResponses.EmptyDataText = "No Objects Found"
            '   grvResponses.MasterTableView.NoDetailRecordsText = "No Object Found"
 
            'Dim Application As BoundField = New BoundField()
            Dim Application As GridBoundColumn = New GridBoundColumn()
            Application.DataField = dt.Columns(1).ColumnName
            Application.HeaderText = CType(Request.QueryString("Series"), String)
            Application.HtmlEncode = False
            'grvResponses.Columns.Add(Application)
            grvResponses.MasterTableView.Columns.Add(Application)
 
 
            'Dim XAxisField As BoundField = New BoundField()
            Dim XAxisField As GridBoundColumn = New GridBoundColumn()
            XAxisField.DataField = AxisX
            XAxisField.HeaderText = XAxisLabel
            XAxisField.HtmlEncode = False
            XAxisField.DataFormatString = "{0:#.0}"
            '  grvResponses.Columns.Add(XAxisField)
            grvResponses.MasterTableView.Columns.Add(XAxisField)
 
            'Dim YAxisField As BoundField = New BoundField()
            Dim YAxisField As GridBoundColumn = New GridBoundColumn()
            YAxisField.DataField = AxisY
            YAxisField.HeaderText = YAxisLabel
            YAxisField.HtmlEncode = False
            'YAxisField.DataFormatString = "{0:#.0}"
            'grvResponses.Columns.Add(YAxisField)
            grvResponses.MasterTableView.Columns.Add(YAxisField)
 
        Else ' display style is comment
            lblHeader.InnerText = "Projects"
            '    grvResponses.EmptyDataText = "No Projects Found"
            grvResponses.MasterTableView.NoMasterRecordsText = "No Projects Found"
            'Dim Application As BoundField = New BoundField()
            Dim Application As GridBoundColumn = New GridBoundColumn()
            Application.DataField = "ObjectName"
            Application.HeaderText = "Project"
            Application.HtmlEncode = False
            '   grvResponses.Columns.Add(Application)
            grvResponses.MasterTableView.Columns.Add(Application)
 
 
            Dim XAxisField As TemplateField = New TemplateField()
            XAxisField.ShowHeader = True
            XAxisField.HeaderText = XAxisLabel
            'XAxisField.HtmlEncode = False
            XAxisField.ItemTemplate = New TableControlItemTemplate(ListItemType.Item, AxisX, XAxisLabel, xMid, xMid1)
            'XAxisField.DataFormatString = "{0:#.0}"
            '  grvResponses.Columns.Add(XAxisField)
            grvResponses.MasterTableView.Columns.Add(XAxisField)
 
            Dim YAxisField As TemplateField = New TemplateField()
            YAxisField.ShowHeader = True
            YAxisField.HeaderText = YAxisLabel
            'YAxisField.HtmlEncode = False
            'YAxisField.DataFormatString = "{0:#.0}"
            YAxisField.ItemTemplate = New TableControlItemTemplate(ListItemType.Item, AxisY, YAxisLabel, yMid, yMid1)
            'grvResponses.Columns.Add(YAxisField)
            grvResponses.MasterTableView.Columns.Add(YAxisField)
        End If
        If (haszAxis) Then
            '  Dim ZAxisField As BoundField = New BoundField()
            Dim ZAxisField As GridBoundColumn = New GridBoundColumn()
            ZAxisField.DataField = ZAxis
            ZAxisField.HeaderText = ZAxisLabel
            ZAxisField.HtmlEncode = False
            ZAxisField.DataFormatString = "{0:#.0}"
            ' grvResponses.Columns.Add(ZAxisField)
            grvResponses.MasterTableView.Columns.Add(ZAxisField)
        End If
        grvResponses.DataBind()
 
    End Sub

Abhishek Dixit,
Hcl Noida

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Apr 2011, 06:18 AM
Hello Abhishek,

The problem occurs because you are binding the grid in PageLoad event, which is Simple data binding technique. If you are using any advanced feature in grid (like filtering,exporting), then a better approach is using "AdvancedData binding" using NeedDataSource event.
For more information about this can be available here.
Advanced Data-binding (using NeedDataSource event)
Grid / Advanced Data Binding

-Shinu.
0
Abhishek
Top achievements
Rank 1
answered on 25 Apr 2011, 05:43 AM
Hi team,
Change you sugested was already there...still its not working.  Cache("data") is the datatable which is having data in it.
Please assist !!!!

Protected Sub grvResponses_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grvResponses.NeedDataSource
       If Not Cache("data") Is Nothing Then
           grvResponses.VirtualItemCount = CType(Cache("data"), DataTable).Rows.Count
           grvResponses.DataSource = CType(Cache("data"), DataTable)
       End If
 
   End Sub
0
Daniel
Telerik team
answered on 28 Apr 2011, 09:13 AM
Hello Abhishek,

I also believe this is a databinding-related issue however it would be hard to guess what exactly goes wrong without debugging your code. Can you please try to isolate this problem in a simple demo?
Isolating a problem in a sample project

Regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Abhishek
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Abhishek
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or