I have the radgrid and commandItemTemplate as follows:
<telerik:RadGrid RenderMode="Lightweight" runat="server" ID="calendarTableView" OnItemCommand="ItemCommand" > <MasterTableView AutoGenerateColumns="false" TableLayout="Fixed" CommandItemDisplay="Top"> <CommandItemTemplate> <asp:TextBox ID="txtFilter" runat="server"></asp:TextBox> <asp:Button ID="btnFilter" runat="server" Text="Apply Filter" CommandName="FilterAll" /> <asp:Button ID="btnClear" runat="server" Text="Clear Filter" CommandName="ClearFilter" /> </CommandItemTemplate> </MasterTableView></telerik:RadGrid>and in the vb file I have
Protected Sub ItemCommand(ByVal sender As Object, ByVal e As GridCommandEventArgs) Dim filterExpression As String = String.Empty If e.CommandName = "FilterAll" Then Dim cmdItem As GridCommandItem = TryCast(e.Item, GridCommandItem) Dim txtFilter = TryCast(cmdItem.FindControl("txtFilter"), TextBox) For Each col As GridColumn In calendarTableView.MasterTableView.Columns For Each dataItem As GridDataItem In calendarTableView.Items If dataItem(col.UniqueName).Text.Contains(txtFilter.Text) Then filterExpression = "([" + col.UniqueName + "] = '%" + txtFilter.Text + "%')" calendarTableView.MasterTableView.FilterExpression = filterExpression End If Next Next calendarTableView.MasterTableView.Rebind() ElseIf e.CommandName = "ClearFilter" Then Dim cmdItem As GridCommandItem = TryCast(e.Item, GridCommandItem) Dim txtFilter As TextBox = TryCast(cmdItem.FindControl("txtFilter"), TextBox) txtFilter.Text = String.Empty calendarTableView.MasterTableView.FilterExpression = String.Empty End IfEnd Sub
but I am running into 2 problems. 1, it's not getting the text from the txtFilter textbox correctly and 2, the line " calendarTableView.MasterTableView.Rebind() " comes up with an exception saying it expected an expression.