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

How to Reset Filter Template Combobox

5 Answers 216 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kosta
Top achievements
Rank 1
Kosta asked on 06 Feb 2013, 10:14 AM

Hi,

Is is possible to reach a Filtered Template Combobox outside the event

Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs)

My code for a FilterTemplate is
<telerik:GridBoundColumn DataField="MeasuringPointName" FilterControlAltText="Filter MeasuringPointName column"
    HeaderText="Изм. т-ка" SortExpression="MeasuringPointName" UniqueName="MeasuringPointName" >
    <ItemStyle Wrap="False" />
    <FilterTemplate>
        <telerik:RadComboBox ID="RadComboBoxMeasuringPointName" DataSourceID="ObjectDataSourceMeasuringPointsNames" DataTextField="MeasuringPointName"
            DataValueField="MeasuringPointName" AppendDataBoundItems="true"  Width="100%" DropDownAutoWidth="Enabled"
            SelectedValue='<%# TryCast(Container,GridItem).OwnerTableView.GetColumn("MeasuringPointName").CurrentFilterValue %>'
            runat="server" OnClientSelectedIndexChanged="MeasuringPointNameIndexChanged">
            <Items>
                <telerik:RadComboBoxItem Text="Всички" />
            </Items>
        </telerik:RadComboBox>
        <telerik:RadScriptBlock ID="RadScriptBlockMeasuringPointName" runat="server">
            <script type="text/javascript">
                function MeasuringPointNameIndexChanged(sender, args) {
                    var tableView = $find("<%# TryCast(Container,GridItem).OwnerTableView.ClientID %>");
                    tableView.filter("MeasuringPointName", args.get_item().get_value(), "EqualTo");
                }
            </script>
        </telerik:RadScriptBlock>
    </FilterTemplate>
</telerik:GridBoundColumn>

I have a RadComboBox and a RadButton which are used to fill SqlDataSource and invoke RadGrid.Prerender with RadGrid.Rebind(). I also use RadAjaxmanager with following code:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
       <AjaxSettings>
           </telerik:AjaxSetting>
           <telerik:AjaxSetting AjaxControlID="btnExecute">
               <UpdatedControls>
                   <telerik:AjaxUpdatedControl ControlID="Panel1" />
               </UpdatedControls>
           </telerik:AjaxSetting>
           <telerik:AjaxSetting AjaxControlID="MeasuringPointsDataGrid">
               <UpdatedControls>
                   <telerik:AjaxUpdatedControl ControlID="Panel1" />
               </UpdatedControls>
           </telerik:AjaxSetting>
       </AjaxSettings>
       <ClientEvents OnRequestStart="onRequestStart" />
   </telerik:RadAjaxManager>
   <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Telerik"
       Transparency="30" meta:resourcekey="RadAjaxLoadingPanel1Resource1">
   </telerik:RadAjaxLoadingPanel>

On first select everithing work correctly. I select item from FilterTemplate and filtering works correct. If I change the the criteria to be completed the RadGrid the FilterTemplate retains the old chosen value instead to change to "All".
My idea is to handle

btnExecute_Click(sender As Object, e As System.EventArgs) Handles btnExecute.Click
event and inside it  any help would me more than welcome  to set the RadComboBoxMeasuringPointName SelectedIndex to 0. 

Any help would me more than welcome. Thank you.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Feb 2013, 11:50 AM
Hi,

I guess you want to access the RadComboBox inside the FilterTemplate in an external button click.

VB:
Protected Sub btnExecute_Click(sender As Object, e As EventArgs)
    Dim Radgrid1 As RadGrid = DirectCast(FindControl("RadGrid1"), RadGrid)
    For Each fitem As GridFilteringItem In Radgrid1.MasterTableView.GetItems(GridItemType.FilteringItem)
            'do your code here
        Dim combo As RadComboBox = DirectCast(fitem.FindControl("RadComboBoxMeasuringPointName"), RadComboBox)
    Next
End Sub

Thanks,
Shinu.
0
Kosta
Top achievements
Rank 1
answered on 06 Feb 2013, 01:18 PM
Thank you so much for your answer.

Your code works fine but didn't help me to deside my task. I miss something. All I want to do is to display all rows with data into RadGrid after FilterTemplate's Radcombobox selected index is changed to <> 0 and after that RadGrid is rebind i.e. fill with new data.

At this time my Page looks like this pseudo table:

[ZonesCheckedComboBox]  [btnExecute]
Row   MeasuringPoint                         Other Data
          [FilterTemplateComboBox]
1         1                                                ...
2         2                                                ...
3         1                                                ...
  
after page is loaded and data is displayed into radGrid I change [FilterTemplateComboBox] value and click on [btnExecute] to execute RadGrid_PreRender. DataSource for my RadGrid Is ObjectDataSource is that is important. I select to filter only measuringpoint with value 1 and grid looks good

[ZonesCheckedComboBox] [btnExecute]
Row      MeasuringPoint                     Other Data
             [FilterTemplateComboBox]
1           1                                            ...
3           1                                            ...

After that I select new zones and click on [btnExecute] and here comes problem. My page look like
[ZonesCheckedComboBox] [btnExecute]
Row         MeasuringPoint                                 Other Data
                [FilterTemplateComboBox]
1             1                                                         ...
1             1                                                         ...
I need manualy to change [FilterTemplateComboBox] to display all rows not just those that are left from the old filter.

My question is is it possible to set a [FilterTemplateComboBox] to display all data  after every click on [btnExecute] and fill radGrid with data.

Thank you so much.
0
Angel Petrov
Telerik team
answered on 11 Feb 2013, 09:32 AM
Hi Kosta,

In order to achieve the desired functionality you can clear the filters manually in the button click event handler like shown in this code snippet:
Protected Sub btnExecute_Click(sender As Object, e As System.EventArgs) Handles btnExecute.Click
        Dim Radgrid1 As RadGrid = DirectCast(FindControl("RadGrid1"), RadGrid)
        For Each fitem As GridFilteringItem In Radgrid1.MasterTableView.GetItems(GridItemType.FilteringItem)
            'do your code here
            Dim combo As RadComboBox = DirectCast(fitem.FindControl("RadComboBoxMeasuringPointName"), RadComboBox)
            Radgrid1.MasterTableView.FilterExpression = ""
            Radgrid1.Rebind()
        Next
    End Sub

And later in the OnItemDataBound event set the first item in the combo as selected:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
        If TypeOf e.Item Is GridFilteringItem Then
            If RadGrid1.MasterTableView.FilterExpression = "" Then
                DirectCast(DirectCast(e.Item, GridFilteringItem).FindControl("RadComboBoxMeasuringPointName"), RadComboBox).Items(0).Selected = True
            End If
        End If
    End Sub

This should do the trick. The approach is also demonstrated in the project attached.

All the best,
Angel Petrov
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.
0
Mina
Top achievements
Rank 1
answered on 24 Apr 2013, 05:52 PM
Thank you. Better late than never but I have a too much tasks to do. In my case it was nessesury to write an extra code to button's click event. Here is it. Thank you again.

Protected Sub btnExecute_Click(sender As Object, e As System.EventArgs) Handles btnExecute.Click
    For i As Integer = 0 To RadGrid1.Columns.Count - 1
        RadGrid1.Columns(i).ResetCurrentFilterValue()
    Next
    RadGrid1.MasterTableView.FilterExpression = ""
    RadGrid1.MasterTableView.Rebind()
End Sub
0
yassin wakeel
Top achievements
Rank 1
answered on 20 Dec 2017, 08:07 AM
It works fine, thank you
Tags
Grid
Asked by
Kosta
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kosta
Top achievements
Rank 1
Angel Petrov
Telerik team
Mina
Top achievements
Rank 1
yassin wakeel
Top achievements
Rank 1
Share this question
or