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

[Solved] Filter for GridTemplateColumns not Consistent

1 Answer 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 10 Apr 2013, 06:38 PM
I have a grid that I am creating in the Page_Init. I set the attribute

RadGrid1.AllowFilteringByColumn =

 

True

 



I have 2 checkbox columns that I use a GridTemplateColumn. First the first column I have fieldName and colName set to Selected, and the second column I have the fieldName and colName set to Forced.

Dim columnCheckBox As New GridTemplateColumn
columnCheckBox.ItemTemplate = New MyTemplate(fieldName)
columnCheckBox.DataField = fieldName
columnCheckBox.HeaderText = colName
columnCheckBox.UniqueName = fieldName
oRadGrid.MasterTableView.Columns.Add(columnCheckBox)

The code for MyTemplate is below. This allows the grid to show a checkbox that is editable right away.

Public Class MyTemplate
    Implements ITemplate
    Protected boolValue As CheckBox
    Private colname As String
    Public Sub New(ByVal cName As String)
        colname = cName
    End Sub
    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements ITemplate.InstantiateIn
        boolValue = New CheckBox()
        boolValue.ID = colname
        AddHandler boolValue.DataBinding, _
                   AddressOf boolValue_DataBinding
        boolValue.Enabled = True
        container.Controls.Add(boolValue)
    End Sub
    Sub boolValue_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
        Dim cBox As CheckBox = DirectCast(sender, CheckBox)
        Dim container As GridDataItem = DirectCast(cBox.NamingContainer, GridDataItem)
        If ((DirectCast(container.DataItem, DataRowView))(colname)) = 1 Or ((DirectCast(container.DataItem, DataRowView))(colname)) = True Then
            cBox.Checked = True
        Else
            cBox.Checked = False
        End If
    End Sub
End Class

I also populate the grid using the RadGrid1_NeedDataSource feature.

Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
     If mintCircSetID > 0 Then
         Dim strSQL As String = ""
         Dim intIndex As Integer = 0
         Dim strSortedColumn As String = ""
         Dim strSortClause As String = ""
         strSQL = "EXEC WB_sp_RetrieveGeographySelection_ForTelerik '" & mstrSessionID & "'," & mintEventID
         If mblnFullRunUtilizedInd Or cbSingleZip.Checked Then
             strSQL = strSQL & ",0"
         Else
             strSQL = strSQL & ",1"
         End If
         If cbSundayFR.Checked Or cbSundayHD.Checked Or cbSundaySC.Checked Or cbSundayMX.Checked Then
             strSQL = strSQL & ",1"
         Else
             strSQL = strSQL & ",0"
         End If
         If cbMondayFR.Checked Or cbMondayHD.Checked Or cbMondaySC.Checked Or cbMondayMX.Checked Then
             strSQL = strSQL & ",1"
         Else
             strSQL = strSQL & ",0"
         End If
         If cbTuesdayFR.Checked Or cbTuesdayHD.Checked Or cbTuesdaySC.Checked Or cbTuesdayMX.Checked Then
             strSQL = strSQL & ",1"
         Else
             strSQL = strSQL & ",0"
         End If
         If cbWednesdayFR.Checked Or cbWednesdayHD.Checked Or cbWednesdaySC.Checked Or cbWednesdayMX.Checked Then
             strSQL = strSQL & ",1"
         Else
             strSQL = strSQL & ",0"
         End If
         If cbThursdayFR.Checked Or cbThursdayHD.Checked Or cbThursdaySC.Checked Or cbThursdayMX.Checked Then
             strSQL = strSQL & ",1"
         Else
             strSQL = strSQL & ",0"
         End If
         If cbFridayFR.Checked Or cbFridayHD.Checked Or cbFridaySC.Checked Or cbFridayMX.Checked Then
             strSQL = strSQL & ",1"
         Else
             strSQL = strSQL & ",0"
         End If
         If cbSaturdayFR.Checked Or cbSaturdayHD.Checked Or cbSaturdaySC.Checked Or cbSaturdayMX.Checked Then
             strSQL = strSQL & ",1"
         Else
             strSQL = strSQL & ",0"
         End If
         strSQL = strSQL & "," & mintParentMap
         If cbSundayFR.Checked Or cbMondayFR.Checked Or cbTuesdayFR.Checked Or cbWednesdayFR.Checked Or cbThursdayFR.Checked Or cbFridayFR.Checked Or cbSaturdayFR.Checked Then
             strSQL = strSQL & ",1,1,1"
         Else
             If cbSundayHD.Checked Or cbMondayHD.Checked Or cbTuesdayHD.Checked Or cbWednesdayHD.Checked Or cbThursdayHD.Checked Or cbFridayHD.Checked Or cbSaturdayHD.Checked Then
                 strSQL = strSQL & ",1"
             Else
                 strSQL = strSQL & ",0"
             End If
             If cbSundayMX.Checked Or cbMondayMX.Checked Or cbTuesdayMX.Checked Or cbWednesdayMX.Checked Or cbThursdayMX.Checked Or cbFridayMX.Checked Or cbSaturdayMX.Checked Then
                 strSQL = strSQL & ",1"
             Else
                 strSQL = strSQL & ",0"
             End If
             If cbSundaySC.Checked Or cbMondaySC.Checked Or cbTuesdaySC.Checked Or cbWednesdaySC.Checked Or cbThursdaySC.Checked Or cbFridaySC.Checked Or cbSaturdaySC.Checked Then
                 strSQL = strSQL & ",1"
             Else
                 strSQL = strSQL & ",0"
             End If
         End If
         intIndex = UBound(Split(hidSortInformation.Value, ","))
         Do While intIndex >= 0
             strSortedColumn = Trim(Split(hidSortInformation.Value, ",")(intIndex))
             strSortClause = strSortClause & strSortedColumn & ","
             intIndex -= 1
         Loop
         strSortClause = Left(strSortClause, Len(strSortClause) - 1)
         strSQL = strSQL & ",'" & strSortClause & "',"
         If cbSortingByParent.Checked Then
             strSQL = strSQL & "1"
         Else
             strSQL = strSQL & "0"
         End If
         strSQL = strSQL & ",''"
         RadGrid1.DataSource = GetDataTable(strSQL)
     End If
 End Sub
 Public Function GetDataTable(ByVal query As String) As DataTable
     Dim ConnString As String = ConfigurationManager.ConnectionStrings("iAnalyzeConnectionString").ConnectionString
     Dim conn As SqlConnection = New SqlConnection(ConnString)
     Dim adapter As SqlDataAdapter = New SqlDataAdapter
     adapter.SelectCommand = New SqlCommand(query, conn)
     Dim table1 As New DataTable
     conn.Open()
     Try
         adapter.Fill(table1)
     Finally
         conn.Close()
     End Try
     Return table1
 End Function

When the grid comes up, the cells for each column in each row are checkboxes. The filter option on the Selected column is a textbox and the filter option on the Forced column is a checkbox. I need both columns to be checkboxes. What I am doing wrong?

The underlying data from the database call has both columns as BIT fields.

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 15 Apr 2013, 11:15 AM
Hello David,

For more information about how to achieve the desired functionality, please refer to the following help article:
Implementing filtering for template/custom columns

Kind regards,
Kostadin
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
David
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or