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

Multiple dropdownlis filters

1 Answer 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 11 Apr 2012, 04:58 AM
I am trying to set up a RadGrid with multiple dropdownlist filters but I get an ArgumentOutOfRangeException on the MyCustomFilteringColumn 

Here is code from the MyCustomFilteringColumn  
 :
       Protected Overloads Overrides Sub SetupFilterControls(ByVal cell As TableCell)
            MyBase.SetupFilterControls(cell)
            cell.Controls.RemoveAt(0)
            Dim list As New DropDownList()
            list.ID = "list" + Me.DataField
            list.AutoPostBack = True
            AddHandler list.SelectedIndexChanged, AddressOf list_SelectedIndexChanged
            cell.Controls.AddAt(0, list)
            cell.Controls.RemoveAt(1)
            list.DataTextField = Me.DataField
            list.DataValueField = Me.DataField
            list.DataSource = _listDataSource
            list.DataBind()
        End Sub

My RadGrid columns are setup like the below (here is one of the many that I have): 

         <custom:MyCustomFilteringColumn DataField="AssessmentID" FilterControlAltText="Filter AssessmentID column"
             FilterControlWidth="80px" HeaderStyle-Width="80px" ItemStyle-Width="80px" ItemStyle-ForeColor="Black"
                                                HeaderStyle-Wrap="true" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"
                                                ShowFilterIcon="false" HeaderText="Assessment ID" SortExpression="AssessmentID"
                                                UniqueName="AssessmentID" />


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        For Each column As GridBoundColumn In RadGrid1.MasterTableView.Columns
            If TypeOf column Is MyStuff.MyCustomFilteringColumn Then
                CType(column, MyStuff.MyCustomFilteringColumn).ListDataSource = GetFilterTable(column.DataField)
            End If
        Next
end sub

    Private Function GetFilterTable(ByVal Field As String) As DataTable
        Dim strConnection As String = ConfigurationManager.ConnectionStrings("PKLConnectionString").ConnectionString
        Dim objConnection As New SqlConnection(strConnection)
        Dim SQLCmd As New SqlCommand() 'The SQL Command
        objConnection.ConnectionString = strConnection     'Set the Connection String
        objConnection.Open() 'Open the connection
        SQLCmd.Connection = objConnection 'Sets the Connection to use with the SQL Command
        Dim dt As New DataTable
        Dim adapter As SqlDataAdapter
        adapter = New SqlDataAdapter("SELECT distinct [" + Field + "] FROM tblAssessment", objConnection)
        objConnection.Open()
        Try
            adapter.Fill(dt)
        Finally
            objConnection.Close()
        End Try
        Return dt
    End Function

Error:
System.ArgumentOutOfRangeException was unhandled by user code
  Message=Specified argument was out of the range of valid values.
Parameter name: index
  ParamName=index
  Source=System.Web
  StackTrace:
       at System.Web.UI.ControlCollection.get_Item(Int32 index)
       at System.Web.UI.ControlCollection.RemoveAt(Int32 index)
       at MyStuff.MyCustomFilteringColumn.SetupFilterControls(TableCell cell) in D:\PKLQMW AT 04 05 2012\PKL_QMW\App_Code\MyCustomFilteringColumn.vb:line 33
       at Telerik.Web.UI.GridColumn.InitializeCell(TableCell cell, Int32 columnIndex, GridItem inItem)
       at Telerik.Web.UI.GridBoundColumn.InitializeCell(TableCell cell, Int32 columnIndex, GridItem inItem)
       at Telerik.Web.UI.GridItem.Initialize(GridColumn[] columns)
       at Telerik.Web.UI.GridItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows)
       at Telerik.Web.UI.GridTableView.CreateFilteringItem(Boolean useDataSource, GridColumn[] copiedColumnSet, GridTHead thead)
       at Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource)
       at Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource)
       at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
       at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
       at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
       at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
       at Telerik.Web.UI.GridTableView.PerformSelect()
       at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
       at Telerik.Web.UI.GridTableView.DataBind()
       at Telerik.Web.UI.RadGrid.DataBind()
       at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
       at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
       at System.Web.UI.Control.EnsureChildControls()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 13 Apr 2012, 06:51 PM
Hi Andy,

I am afraid we cannot determine the cause of the issue based on the supplied information. However,  I would suggest that you define FilterTemplate for the columns in question:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultcs.aspx

This can be done with little or no custom code, and allows for the same degree of flexibility as the custom column.

Greetings,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Andy
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or