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

Filtering on multiple column in dynamic Telerik RAD grid

2 Answers 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rajeev
Top achievements
Rank 1
Rajeev asked on 09 Jun 2016, 02:43 PM

I am preparing dynamic grid using VB.net and RAD grid where columns are getting generated in Run Time. I am trying to apply filter (inbuilt filter) on multiple column at time but application is throwing exception (is neither a DataColumn nor a DataRelation for table Table). This error occurs when I try to apply filter. I am unable to identify root cause. Any input would be appreciated. I am using NeedDataSource() event of Radgrid and this event is throwing above mentioned exception on applying filter.

.Telerik page setting:

<telerik:RadGrid ID="gridData" runat="server" OnGridExporting="grid_GridExporting" RenderMode="Auto" ClientIDMode="AutoID" >
                    </telerik:RadGrid>

 

 

Code-behibd setting:

On page_load():

If Not ds Is Nothing Then
                DefineGridStructure(Session("DynamicResultReportGridData"))
                gridData.DataBind()

end

--------------------------

   Private Sub DefineGridStructure(ByVal allCloumnData As DataSet)

        'Dim grid As New RadGrid()

        gridData.DataSource = allCloumnData
        Session.Add("DynamicResultReportGridData", allCloumnData)
        gridData.Skin = "Default"
        gridData.Width = Unit.Percentage(100)
        gridData.PageSize = 15
        gridData.AllowPaging = True
        gridData.AllowFilteringByColumn = True
        gridData.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric
        gridData.AutoGenerateColumns = False

        'Add Customers table
        gridData.MasterTableView.Width = Unit.Percentage(100)

        Dim intVal As Integer = allCloumnData.Tables(0).Columns.Count
        For a = 0 To intVal - 1
            Dim boundColumn As New GridBoundColumn()
            boundColumn.DataField = allCloumnData.Tables(0).Columns(a).Caption().Trim().ToString()
            boundColumn.HeaderText = allCloumnData.Tables(0).Columns(a).Caption().Trim().ToString()
            boundColumn.UniqueName = allCloumnData.Tables(0).Columns(a).Caption().Trim().ToString()
            boundColumn.ItemStyle.CssClass = "text2"

            boundColumn.HeaderStyle.CssClass = "GridHeader"
            boundColumn.AllowFiltering = True
            gridData.MasterTableView.Columns.Add(boundColumn)
        Next
    End Sub

----------------------------------------------------

Protected Sub gridData_NeedDataSource(ByVal Source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles gridData.NeedDataSource

        gridDiv.Visible = True
        gridDiv1.Visible = True
        gridData.Visible = True
        Dim allCloumnData As DataSet = Session("DynamicResultReportGridData")
        If allCloumnData Is Nothing Then
        Else
            gridData.DataSource = allCloumnData
        End If


    End Sub

 

Thanks in advance
Rajeev

2 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 14 Jun 2016, 09:10 AM
Hello Rajeev,

From the provided code it seems that you are calling DataBind() for the grid. Note that this method is used only for simple data binding. As the name implies this binding method is suitable only for the most simple scenarios where features like filterin, sorting, paging, etc. will not be used.

In your scenario it is recommended to use advanced data binding. You can bind the grid to a declarative data source or provide the data via the NeedDataSource event. Check out the following resources that illustrate the two approaches:


After the grid is data-bound you can use the approach described below in order to define initial filter that will be applied:



Regards,
Viktor Tachev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Ohad
Top achievements
Rank 1
Iron
answered on 02 Jan 2022, 04:11 PM

Hi all, I know it an old post but my answer may help other.

The issue here is the Rajeev is setting the properties of the column before adding it into the grid:

The fix is:
(With emphasis on the second line) 
            

Dim boundColumn AsNew GridBoundColumn()
gridData.MasterTableView.Columns.Add(boundColumn) boundColumn.DataField = allCloumnData.Tables(0).Columns(a).Caption().Trim().ToString() boundColumn.HeaderText = allCloumnData.Tables(0).Columns(a).Caption().Trim().ToString() boundColumn.UniqueName = allCloumnData.Tables(0).Columns(a).Caption().Trim().ToString() boundColumn.ItemStyle.CssClass = "text2" boundColumn.HeaderStyle.CssClass = "GridHeader" boundColumn.AllowFiltering = True


Attila Antal
Telerik team
commented on 03 Jan 2022, 01:08 PM

I can confirm that the proper way of creating the Columns in the Page_Load even would be to Create the Column object and add it to the MasterTable's Column collection before changing its properties.

In the Page_Init event, the Order does not matter.

Thank you, Ohad for helping the community!

Tags
Grid
Asked by
Rajeev
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Ohad
Top achievements
Rank 1
Iron
Share this question
or