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

[Solved] itemtemplate is not working in dropdown filtering

3 Answers 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pravat
Top achievements
Rank 1
Pravat asked on 22 May 2009, 07:11 AM

Hi,
     I am filtering My grid with dropdownlist. It is working fine. but while i am using Itemtemplate in MyCustomeFilteringColumn
getting Parser Error Message: Type 'FilteringTemplateColumns.MyCustomFilteringColumnVB' does not have a public property named 'itemtemplate'.
Please help me out.

Thanks & Regards,
Pravat Sharma

<custom:MyCustomFilteringColumnVB DataField="Country" FilterControlWidth="180px" HeaderText="Custom TemplateColumn Country">
 <headerstyle width="25%" />
      <itemtemplate>

          <asp:LinkButton ID="lnkProducts" runat="server" ForeColor="black"
           CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ContentID") %>'
                Font-Underline="false" CssClass="labelText" CommandName="Select">
                <%#DataBinder.Eval(Container.DataItem, "Title")%>
          </asp:LinkButton>                       
      </ItemTemplate>                      

</custom:MyCustomFilteringColumnVB>

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 26 May 2009, 07:18 AM
Hello Pravat,

Can you please make sure that your custom column does inherits from GridTemplateColumn, as this is needed in order a column to have an itemtemplate.

Sincerely yours,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Pravat
Top achievements
Rank 1
answered on 26 May 2009, 10:58 AM
Thanks for your reply.

While Inherits GridTemplateColumn  itemtemplate is working but my dropdown list is not binding data. Please find my aspx and MyCustomFilteringColumnVB class code.
Thanks & Regards,
Pravat Sharma

Imports Microsoft.VisualBasic  
Imports System.Data  
Imports Telerik.Web.UI  
Imports System.Web.UI.WebControls  
Imports System.Web.UI  
Imports System  
Imports System.Configuration  
Imports System.Data.SqlClient  
 
' <summary>  
' Custom column that shows filtering dropdown instead of textbox  
' </summary>  
 
Namespace ItemTemplateColumnsFiltering  
    Public Class MyCustomeItemTemplateFiltering  
        Inherits GridTemplateColumn  
 
        Public Shared ReadOnly Property ConnectionString() As String 
            Get 
                Return ConfigurationManager.ConnectionStrings("KmStore").ConnectionString  
            End Get 
        End Property 
 
 
        'RadGrid will call this method when it initializes the controls inside the filtering item cells  
        Protected Overrides Sub SetupFilterControls(ByVal cell As TableCell)  
 
            MyBase.SetupFilterControls(cell)  
            cell.Controls.RemoveAt(0)  
            Dim combo As RadComboBox = New RadComboBox  
            combo.ID = ("RadComboBox1" + Me.DataField)  
            combo.ShowToggleImage = False 
            combo.Skin = "Office2007" 
            combo.EnableLoadOnDemand = True 
            combo.AutoPostBack = True 
            combo.Width = "130" 
            combo.MarkFirstMatch = True 
            'If Convert.ToString(cell.ID) <> "ctl00" Then  
            '    combo.Visible = False  
            'End If  
            combo.Height = Unit.Pixel(300)  
            AddHandler combo.SelectedIndexChanged, AddressOf Me.combo_SelectedIndexChanged  
            Dim table As DataTable = GetTable(Me.DataField)  
 
            Dim row As DataRow = table.NewRow()  
            row(Me.DataField) = "" 
            table.Rows.InsertAt(row, 0)  
            combo.DataSource = table  
            cell.Controls.Add(combo)  
 
        End Sub 
        'RadGrid will cal this method when the filtering value should be extracted from the filtering input control(s)  
        Protected Overrides Sub SetCurrentFilterValueToControl(ByVal cell As TableCell)  
            If Not (Me.CurrentFilterValue = ""Then 
                CType(cell.Controls(0), RadComboBox).Items.FindItemByText(Me.CurrentFilterValue).Selected = True 
            End If 
        End Sub 
 
        Protected Overrides Function GetCurrentFilterValueFromControl(ByVal cell As TableCell) As String 
            Dim combo As RadComboBox = CType(cell.Controls(0), RadComboBox)  
            Return combo.Text  
        End Function 
 
        Private Sub combo_SelectedIndexChanged(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)  
            CType(((CType(sender, RadComboBox)).Parent.Parent), GridFilteringItem).FireCommandEvent("Filter"New Pair("Contains"Me.UniqueName))  
        End Sub 
 
        Public Shared Function GetDataTable(ByVal query As StringAs DataTable  
 
            Dim conn As New SqlConnection(ConnectionString)  
            Dim adapter As New SqlDataAdapter  
            adapter.SelectCommand = New SqlCommand(query, conn)  
 
            Dim myDataTable As New DataTable  
 
            conn.Open()  
            Try 
                adapter.Fill(myDataTable)  
            Finally 
                conn.Close()  
            End Try 
            Return myDataTable  
        End Function 
 
        Public Shared Function GetTable(ByVal celltitle As StringAs DataTable  
            Dim myDataTable As New DataTable  
            If celltitle = "Title" Then 
                myDataTable = GetDataTable("SELECT DISTINCT Title FROM Content WHERE title LIKE '" & celltitle & "%'")  
            ElseIf celltitle = "Products" Then 
                myDataTable = GetDataTable("select DISTINCT Name as 'Products'  from ContentAttributeValue where ContentAttributeID_FK='76B996A0-E3E9-48B7-A821-EF05AB9C8CEB' and [name] like '" & celltitle & "%'")  
            ElseIf celltitle = "MediaTypes" Then 
                myDataTable = GetDataTable("SELECT DISTINCT MediaTypes FROM ContentFlatAttributes WHERE MediaTypes LIKE '" & celltitle & "%'")  
            ElseIf celltitle = "Objectives" Then 
                myDataTable = GetDataTable("select DISTINCT Name as 'Objectives'  from ContentAttributeValue where ContentAttributeID_FK='DD4F041B-53E8-4CEE-87E4-0039E722D018' and [name] like '" & celltitle & "%'")  
            End If 
            Return myDataTable  
        End Function 
    End Class 
End Namespace 
 
 <custom:MyCustomeItemTemplateFiltering DataField="Objectives"  HeaderText="Objectives">  
                                <itemtemplate>    
                                        <asp:LinkButton ID="lnkObjectives" runat="server" ForeColor="black"    
                                        CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ContentID") %>'      
                                        Font-Underline="false" CssClass="labelText" CommandName="Select">     
                                            <%# DataBinder.Eval(Container.DataItem, "Objectives") %>    
                                        </asp:LinkButton>    
                                           
                                    </itemtemplate>     
 
                    </custom:MyCustomeItemTemplateFiltering> 
0
Rosen
Telerik team
answered on 29 May 2009, 07:08 AM
Hello Pravat,

I suspect that the RadComboBox is not populated due to the wrong SQL statement as you are filtering on the name of the column instead of field's value also the ItemRequested handler is missing is missing and RadComboBox DataTextField nor DataValueField are set. Therefore your code should look similar to the following:

Protected Overrides Sub SetupFilterControls(ByVal cell As TableCell)  
 
            MyBase.SetupFilterControls(cell)  
            cell.Controls.RemoveAt(0)  
            Dim combo As RadComboBox = New RadComboBox  
            combo.ID = ("RadComboBox1" + Me.DataField)  
            combo.ShowToggleImage = False 
            combo.Skin = "Office2007" 
            combo.EnableLoadOnDemand = True 
            combo.AutoPostBack = True 
            combo.Width = "130" 
            combo.MarkFirstMatch = True 
            combo.Height = Unit.Pixel(300)  
 
 
            combo.DataTextField = Me.DataField  
            combo.DataValueField = Me.DataField  
 
            AddHandler combo.SelectedIndexChanged, AddressOf Me.combo_SelectedIndexChanged  
            AddHandler combo.ItemsRequested, AddressOf Me.combo_ItemsRequested  
 
            Dim table As DataTable = GetTable(Me.DataField, "%")  
 
            Dim row As DataRow = table.NewRow()  
            row(Me.DataField) = "" 
            table.Rows.InsertAt(row, 0)  
            combo.DataSource = table  
            cell.Controls.Add(combo)  
 
 
        End Sub 
 
        Private Sub combo_ItemsRequested(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs)  
            Dim table As DataTable = GetTable(Me.DataField, e.Text)  
            CType(sender, RadComboBox).DataSource = table  
        End Sub 
 
        Public Shared Function GetTable(ByVal celltitle As StringByVal text As StringAs DataTable  
            Dim myDataTable As New DataTable  
            If celltitle = "Title" Then 
                myDataTable = GetDataTable("SELECT DISTINCT Title FROM Content WHERE title LIKE '" & celltitle & "%'")  
            End If 
            'other declaration  
 
            Return myDataTable  
        End Function 


Regards,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Pravat
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Pravat
Top achievements
Rank 1
Share this question
or