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

Initial Value for FilterTemplate Combobox

1 Answer 22 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Carlos asked on 18 Jul 2014, 06:23 PM
Hi. I have a RadGrid with a Combobox FilterTemplate
<telerik:RadGrid ID="rgvEquipos" Width="70%" DataSourceID="SqlDataSource1" AllowFilteringByColumn="True"
            AllowSorting="True" AllowPaging="True" PageSize="30" runat="server" AutoGenerateColumns="False" ShowFooter="true"
            OnPreRender="rgvEquipos_PreRender" ShowStatusBar="true" EnableLinqExpressions="false" OnItemDataBound="rgvEquipos_ItemDataBound">
                <MasterTableView DataKeyNames="equipoId" ShowFooter="true">
                    <Columns>
                        <telerik:GridBoundColumn UniqueName="equipoId" DataField="equipoId" HeaderText="equipoId"
                            AllowFiltering="false" HeaderStyle-Width="80px" />
                        <telerik:GridBoundColumn UniqueName="centro" DataField="centro" HeaderText="centro"
                            HeaderStyle-Width="80px">
                            <FilterTemplate>
                                <telerik:RadComboBox ID="rcbCentro" DataSourceID="SqlDataSource2" DataTextField="centro"
                                    DataValueField="centro" Height="200px" AppendDataBoundItems="true" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("centro").CurrentFilterValue %>'
                                    runat="server" OnClientSelectedIndexChanged="centroIndexChanged">
                                    <Items>
                                        <telerik:RadComboBoxItem Text="Todos" />
                                    </Items>
                                </telerik:RadComboBox>
                                <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
                                    <script type="text/javascript">
                                        function centroIndexChanged(sender, args) {
                                            var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                            tableView.filter("centro", args.get_item().get_value(), "EqualTo");
                                        }
                                    </script>
                                </telerik:RadScriptBlock>
                            </FilterTemplate>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn UniqueName="Denominacion" DataField="Denominacion" HeaderText="Denominacion"
                            AllowFiltering="false" HeaderStyle-Width="300px" />
                        <telerik:GridBoundColumn UniqueName="Ubicacion" DataField="Ubicacion" HeaderText="Ubicacion"
                            AllowFiltering="false" HeaderStyle-Width="300px" />
                        <telerik:GridBoundColumn UniqueName="centroCosto" DataField="centroCosto" HeaderText="centroCosto"
                            AllowFiltering="false" HeaderStyle-Width="80px" />
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
....
<asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:PlanMantenimientoConnectionString %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT [equipoId], [centro], [activoFijo], [Denominacion], [areaEmpresa], [Ubicacion], [GP], [fabricante], [tipoObjeto], [numSerie], [statusSistema], [centroCosto], [calle], [creadoEl], [creadoPor] FROM [inventarioPM] WHERE (calle LIKE '%TRANSMIS%' OR calle = '') AND Ubicacion NOT LIKE '%ERO%' AND GP <> ' '"
        runat="server"></asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:PlanMantenimientoConnectionString %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT DISTINCT [centro] FROM [inventarioPM] WHERE (calle LIKE '%TRANSMIS%' OR calle = '') AND Ubicacion NOT LIKE '%ERO%' AND GP <> ' ' Order By Centro"
        runat="server"></asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource3" ConnectionString="<%$ ConnectionStrings:PlanMantenimientoConnectionString %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT DISTINCT [GP] FROM [inventarioPM] WHERE (calle LIKE '%TRANSMIS%' OR calle = '') AND Ubicacion NOT LIKE '%ERO%' AND GP <> ' ' Order By GP"
        runat="server"></asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource4" ConnectionString="<%$ ConnectionStrings:PlanMantenimientoConnectionString %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT DISTINCT [activoFijo] FROM [inventarioPM] WHERE (calle LIKE '%TRANSMIS%' OR calle = '') AND Ubicacion NOT LIKE '%ERO%' AND activoFijo = 'gggg'"
        runat="server"></asp:SqlDataSource>

And i want the combobox to have a Defalut value depending on a URL parameter... with this code the combo is selectd right by the parameter, but the Grid is not populated by this filter.

protected void Page_Load(object sender, EventArgs e)
        {
            esp = Request["esp"];
            zona = Request["zona"];
        }
        protected void rgvEquipos_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridFilteringItem)
            {
                GridFilteringItem filterItem = (GridFilteringItem)e.Item;
                RadComboBox comboCentro = (RadComboBox)filterItem.FindControl("rcbCentro");// accessing RadComboBox in FilterTemplate
                RadComboBox comboGP = (RadComboBox)filterItem.FindControl("rcbGP");// accessing RadComboBox in FilterTemplate
                RadComboBox comboActivo = (RadComboBox)filterItem.FindControl("rcbactivoFijo");// accessing RadComboBox in FilterTemplate
                if (!IsPostBack)
                {
                    comboCentro.SelectedValue = zona;
                    comboGP.SelectedValue = esp;
                }
            }
        }
        protected void rgvEquipos_PreRender(object sender, System.EventArgs e)
        {
            if (rgvEquipos.MasterTableView.FilterExpression != string.Empty)
            {
                RefreshCombos();
            }
        }
        protected void RefreshCombos()
        {
 
            SqlDataSource2.SelectCommand = "SELECT DISTINCT [centro] FROM [inventarioPM] WHERE (calle LIKE '%TRANSMIS%' OR calle = '') AND Ubicacion NOT LIKE '%ERO%' AND GP <> ' ' AND " + rgvEquipos.MasterTableView.FilterExpression.ToString() + " Order By centro";
            SqlDataSource3.SelectCommand = "SELECT DISTINCT [GP] FROM [inventarioPM] WHERE (calle LIKE '%TRANSMIS%' OR calle = '') AND Ubicacion NOT LIKE '%ERO%' AND GP <> ' ' AND " + rgvEquipos.MasterTableView.FilterExpression.ToString() + " Order By GP";
            SqlDataSource4.SelectCommand = SqlDataSource4.SelectCommand + " AND " + rgvEquipos.MasterTableView.FilterExpression.ToString();
            rgvEquipos.MasterTableView.Rebind();
        }

Could yo please help me with this.
Thankss

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 21 Jul 2014, 05:28 AM
Hi Carlos,

In order to set Initial Filter for your grid, you have to set its FilterExpression property. The value of the FilterExpression property is a string that represents the text of a WHERE clause for filtering items.
Please take a look at the following article for more help:
Applying Default Filter on Initial Load
Operating with the FilterExpression of Telerik RadGrid Manually

Thanks,
Shinu
Tags
Grid
Asked by
Carlos
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or