Filtering Radgrid with DropDown/ComboBox

13 posts, 0 answers
  1. Chema
    Chema avatar
    4 posts
    Member since:
    Feb 2012

    Posted 21 Mar 2012 Link to this post

    When y try to filter, the exception "Invalid column name" shows up
    Here is the aspx
    <p>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadGrid2">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
        <telerik:RadGrid ID="RadGrid1" Width="100%" DataSourceID="SqlDataSource1" AllowFilteringByColumn="True"
            AllowSorting="True" AllowPaging="True" PageSize="7" runat="server" AutoGenerateColumns="False"
            OnPreRender="RadGrid1_PreRender" ShowStatusBar="true" EnableLinqExpressions="false">
            <MasterTableView DataKeyNames="IdEmpresa">
                <Columns>
                    <telerik:GridBoundColumn UniqueName="Empresa" DataField="Empresa" HeaderText="Empresa"
                        AllowFiltering="false" HeaderStyle-Width="200px" />
                    <telerik:GridBoundColumn UniqueName="Supergrupo" DataField="Supergrupo" HeaderText="Super Grupo"
                        HeaderStyle-Width="200px">
                        <FilterTemplate>
                            <telerik:RadComboBox ID="RadComboBoxTitle" DataSourceID="SqlDataSource2" DataTextField="SuperGrupo" AutoPostBack="false"
                                DataValueField="SuperGrupo" Height="200px" AppendDataBoundItems="true"
                                SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("SuperGrupo").CurrentFilterValue %>'
                                runat="server" OnClientSelectedIndexChanged="TitleIndexChanged">
                                <Items>
                                    <telerik:RadComboBoxItem Text="Todos" />
                                </Items>
                            </telerik:RadComboBox>
                            <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
     
                                <script type="text/javascript">
                                    function TitleIndexChanged(sender, args)
                                    {
                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                        tableView.filter("SuperGrupo", args.get_item().get_value(), "EqualTo");
     
                                    }
                                </script>
                            </telerik:RadScriptBlock>
                        </FilterTemplate>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn UniqueName="Grupo" DataField="Grupo" HeaderText="Grupo" HeaderStyle-Width="200px">
                        <FilterTemplate>
                            <telerik:RadComboBox ID="RadComboBoxCity" DataSourceID="SqlDataSource3" DataTextField="Grupo" AutoPostBack="false"
                                DataValueField="Grupo" Height="100px" AppendDataBoundItems="true"
                                SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("Grupo").CurrentFilterValue %>'
                                runat="server" OnClientSelectedIndexChanged="CityIndexChanged">
                                <Items>
                                    <telerik:RadComboBoxItem Text="All" />
                                </Items>
                            </telerik:RadComboBox>
                            <telerik:RadScriptBlock ID="RadScriptBlock2" runat="server">
     
                                <script type="text/javascript">
                                    function CityIndexChanged(sender, args)
                                    {
                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                        tableView.filter("Grupo", args.get_item().get_value(), "EqualTo");
                                    }
                                </script>
     
                            </telerik:RadScriptBlock>
                        </FilterTemplate>
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
        <br />
        <telerik:RadToolTip ID="RadToolTip1" runat="server" OffsetY="3" Position="TopCenter"
            ShowCallout="false" Height="20px" ShowEvent="fromcode" />
        <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:BTIMEXICO_DESConnectionC %>"
            ProviderName="System.Data.SqlClient" runat="server"
            SelectCommand="SELECT E.idEmpresa, E.Nombre AS Empresa, GE.idgrupo, G.Descripcion AS Grupo, SG.Descripcion AS SuperGrupo
                           FROM tbl_empresa E
                           LEFT JOIN tbl_grupoempresa GE
                           ON E.idEmpresa = GE.idEmpresa
                           LEFT JOIN tbl_grupos G
                           ON GE.idgrupo = G.idgrupo
                           LEFT JOIN tbl_Supergrupo SG
                           ON SG.idsupergrupo = G.idsupergrupo
                           ORDER BY Nombre">
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:BTIMEXICO_DESConnectionC %>"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT DISTINCT Descripcion AS SuperGrupo FROM tbl_supergrupo"
            runat="server">
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource3" ConnectionString="<%$ ConnectionStrings:BTIMEXICO_DESConnectionC %>"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT DISTINCT Descripcion AS Grupo FROM tbl_grupos"
            runat="server">
        </asp:SqlDataSource>
    </p>

    And the Code-behind
    using System;
    using System.Linq;
    using System.Data;
    using Telerik.Web.UI;
     
    namespace BCD.PP.VIEW
    {
        public partial class Client_Question_Config_A : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                }
            }
     
            protected void ImportedFilter_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
            {
                DataRowView rowView = (DataRowView)e.Item.DataItem;
                if (rowView["Bool"] is DBNull)
                {
                    e.Item.Text = "No";
                    e.Item.Value = "0";
                }
                else if ((bool)rowView["Bool"])
                {
                    e.Item.Text = "Yes";
                    e.Item.Value = "1";
                }
            }
     
            protected void RadGrid1_PreRender(object sender, System.EventArgs e)
            {
                if (RadGrid1.MasterTableView.FilterExpression != string.Empty)
                {
                    RefreshCombos();
                }
            }
            protected void RefreshCombos()
            {
                SqlDataSource2.SelectCommand = SqlDataSource2.SelectCommand + " WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();
                SqlDataSource3.SelectCommand = SqlDataSource3.SelectCommand + " WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();
                RadGrid1.MasterTableView.Rebind(); //<<< Here is where the exception pops up
            }
        }
    }

    Following the example from here

    I suspect the problem may be because the SQLDataSource is composed by joins instead of being a single table
    any idea on how to solve this?
  2. James Campbell
    James Campbell avatar
    90 posts
    Member since:
    Jul 2012

    Posted 21 Mar 2012 Link to this post

    Chema,

    I am not sure what is going on there, check for typos for sure, but what I would try is take that query for datasource1 and create a stored procedure in SQL Server. Then use that SP as the datasource. See if you still get the error.

    I wonder if it has to do with all that aliasing, doubt the joins are an issue, unless it is taking more time and the control is applying the data before your query completes and since you are aliasing and using the new name for the column's data, maybe the query isn't done, so the name hasn't changed yet.
     
    If you want I could play around if that doesn't do it. If you could script out your data tables, I could try to recreate.

    Thanks,
    Jim
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Chema
    Chema avatar
    4 posts
    Member since:
    Feb 2012

    Posted 22 Mar 2012 Link to this post

    I changed it to a SP, still the result is the same :/
  5. James Campbell
    James Campbell avatar
    90 posts
    Member since:
    Jul 2012

    Posted 23 Mar 2012 Link to this post

    Chema,

    If you'd like, I could see what I could do.. Can you script out the database structure and either attach it to this post or email @ jimmy151 AT Hotmail DOT com?

    Thanks,
    Jim
  6. Chema
    Chema avatar
    4 posts
    Member since:
    Feb 2012

    Posted 23 Mar 2012 Link to this post

    Here they are

    Thanks for your help
  7. James Campbell
    James Campbell avatar
    90 posts
    Member since:
    Jul 2012

    Posted 23 Mar 2012 Link to this post

    Chema,

    np, I will take a look tonight and tomorrow.
    Thanks,
    Jim
  8. James Campbell
    James Campbell avatar
    90 posts
    Member since:
    Jul 2012

    Posted 28 Mar 2012 Link to this post

    Chema,

    Just letting you know that I haven't forgotten about you. I should have a chance to go over this today. I will let you if I am able to get it running or not.
    Thanks,
    Jim
  9. James Campbell
    James Campbell avatar
    90 posts
    Member since:
    Jul 2012

    Posted 28 Mar 2012 Link to this post

    Chema,

    I have isolated the error and believe this is due to the aliasing in your query, I am going to try a few things and let you know what i come up with. But here is the exact error:

    System.Data.SqlClient.SqlException was unhandled by user code
      Message=Invalid column name 'Grupo'.
      Source=.Net SqlClient Data Provider
      ErrorCode=-2146232060
      Class=16
      LineNumber=1
      Number=207
      Procedure=""
      Server=  State=1
      StackTrace:
           at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
           at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
           at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
           at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
           at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
           at System.Data.SqlClient.SqlDataReader.get_MetaData()
           at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
           at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
           at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
           at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
           at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
           at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
           at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
           at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
           at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
           at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
           at System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)
           at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
           at Telerik.Web.UI.RadComboBox.OnDataBinding(EventArgs e)
           at Telerik.Web.UI.RadComboBox.PerformSelect()
           at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
           at Telerik.Web.UI.RadComboBox.DataBind()
           at System.Web.UI.Control.DataBindChildren()
           at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
           at System.Web.UI.Control.DataBind()
           at System.Web.UI.Control.DataBindChildren()
           at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
           at System.Web.UI.Control.DataBind()
           at Telerik.Web.UI.GridItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows)
           at Telerik.Web.UI.GridTableView.CreateFilteringItem(Boolean useDataSource, GridColumn[] copiedColumnSet, GridTHead thead)
           at Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource)
           at Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource)
           at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
           at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
           at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
           at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
           at Telerik.Web.UI.GridTableView.PerformSelect()
           at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
           at Telerik.Web.UI.GridTableView.DataBind()
           at Telerik.Web.UI.GridTableView.Rebind()
           at Default.RefreshCombos() in c:\users\theuser\documents\visual studio 2010\Projects\KendoUI\RadControlsWebApp4\RadControlsWebApp4\Default.aspx.cs:line 66
           at Default.RadGrid1_PreRender(Object sender, EventArgs e) in c:\users\theuser\documents\visual studio 2010\Projects\KendoUI\RadControlsWebApp4\RadControlsWebApp4\Default.aspx.cs:line 53
           at System.Web.UI.Control.OnPreRender(EventArgs e)
           at System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e)
           at Telerik.Web.UI.RadCompositeDataBoundControl.OnPreRender(EventArgs e)
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      InnerException:

  10. James Campbell
    James Campbell avatar
    90 posts
    Member since:
    Jul 2012

    Posted 28 Mar 2012 Link to this post

    It's this SQL statement, that field does not exist in the tbl supergrupo, just need to change that filter, give me a few, solution inc:

    SqlDataSource2.SelectCommand = SqlDataSource2.SelectCommand + " WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();

    which leads to this statement being rendered:
    SELECT DISTINCT Descripcion AS SuperGrupo FROM tbl_supergrupo WHERE ([Grupo] = 'ABBOTT')

  11. James Campbell
    James Campbell avatar
    90 posts
    Member since:
    Jul 2012

    Posted 28 Mar 2012 Link to this post

    Chema,

    First thing you need to do is in your function: TitleIndexChanged change SuperGrupo to Supergrupo as Javascript is case sensitive, that is why that filter doesn't actually fire, although right now I am still having an issue with the expression, I noticed this issue in the current code.

    Will let you know once I have the filter working on both selections.
    Thanks,
    Jim
  12. James Campbell
    James Campbell avatar
    90 posts
    Member since:
    Jul 2012

    Posted 28 Mar 2012 Link to this post

    Chema,

    Ok, we have a couple of things going on here.

    First thing is the aliasing. Once you add a where to the query, SQL handles the order of execution of the TSQL differently , so the alias is not being applied when asked for:

    http://blogs.x2line.com/al/archive/2007/06/30/3187.aspx

    So you would want to change your Datasources to read like the following:

    <asp:SqlDataSource ID="SqlDataSource2"
            ConnectionString="<%$ ConnectionStrings:BTIMEXICO_DESConnectionString %>" SelectCommand="SELECT DISTINCT a.Supergrupo FROM(Select Descripcion AS Supergrupo FROM tbl_supergrupo) AS a"
     
        runat="server">
     
    </asp:SqlDataSource>
     
    <asp:SqlDataSource ID="SqlDataSource3"
            ConnectionString="<%$ ConnectionStrings:BTIMEXICO_DESConnectionString %>" SelectCommand="SELECT DISTINCT a.Grupo FROM(Select Descripcion AS Grupo FROM tbl_grupos) AS a"
     
        runat="server">
     
    </asp:SqlDataSource>

    Now, the other issue, is you changed the data Schema from the example you pulled. By doing that, the structure is a bit different, so you have to handle the filter expression a bit differrent. If you make the following change, the first filter will work. You will have to work out additional fields, with ANDs, etc. But you have the jiest of it from this:

    protected void RefreshCombos()
    {
     
        if (RadGrid1.MasterTableView.FilterExpression.ToString().Contains("Supergrupo"))
        {
        SqlDataSource2.SelectCommand = SqlDataSource2.SelectCommand + " WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();
        }
        else
        {
        SqlDataSource3.SelectCommand = SqlDataSource3.SelectCommand + " WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();
        }
     
        RadGrid1.MasterTableView.Rebind(); //<<< Here is where the exception pops up
     
    }

    Now you can also test the filter pair and play around with that to get the behavior you are looking for. Also note you can set a breakpoint on each to see what is coming accross. Here is more on the filterpair:

    http://www.telerik.com/help/aspnet-ajax/grid-operate-with-filter-expression-manually.html

    I cannot attach the files so i will follow up with another post with all the source.

    Hope this helps, any questions, let me know.

    Thanks,
    Jim
    If this helped answer your question, please mark this as answered, thank you.


  13. James Campbell
    James Campbell avatar
    90 posts
    Member since:
    Jul 2012

    Posted 28 Mar 2012 Link to this post

    The aspx page:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
        <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <%--Needed for JavaScript IntelliSense in VS2010--%>
                <%--For VS2008 replace RadScriptManager with ScriptManager--%>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>
        <script type="text/javascript">
            //Put your JavaScript code here.
        </script>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
      
            <AjaxSettings>
      
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
      
                    <UpdatedControls>
      
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
      
                    </UpdatedControls>
      
                </telerik:AjaxSetting>
      
                <telerik:AjaxSetting AjaxControlID="RadGrid2">
      
                    <UpdatedControls>
      
                        <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel1" />
      
                    </UpdatedControls>
      
                </telerik:AjaxSetting>
      
            </AjaxSettings>
      
        </telerik:RadAjaxManager>
     
          
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
      
        <telerik:RadGrid ID="RadGrid1" Width="100%" DataSourceID="SqlDataSource1" AllowFilteringByColumn="True"
      
            AllowSorting="True" AllowPaging="True" PageSize="7" runat="server" AutoGenerateColumns="False"
      
            OnPreRender="RadGrid1_PreRender" ShowStatusBar="True"
                EnableLinqExpressions="False" CellSpacing="0" GridLines="None">
      
    <ClientSettings>
    <Selecting CellSelectionMode="None"></Selecting>
    </ClientSettings>
     
            <MasterTableView DataKeyNames="IdEmpresa">
      
    <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
     
    <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
     
    <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
      
                <Columns>
      
                    <telerik:GridBoundColumn UniqueName="Empresa" DataField="Empresa" HeaderText="Empresa"
      
                        AllowFiltering="false" HeaderStyle-Width="200px" >
      
    <HeaderStyle Width="200px"></HeaderStyle>
                    </telerik:GridBoundColumn>
      
                    <telerik:GridBoundColumn UniqueName="Supergrupo" DataField="Supergrupo" HeaderText="Super Grupo"
      
                        HeaderStyle-Width="200px">
      
                        <FilterTemplate>
      
                            <telerik:RadComboBox ID="RadComboBoxTitle" DataSourceID="SqlDataSource2" DataTextField="Supergrupo" AutoPostBack="false"
      
                                DataValueField="Supergrupo" Height="200px" AppendDataBoundItems="true"
      
                                SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("Supergrupo").CurrentFilterValue %>'
      
                                runat="server" OnClientSelectedIndexChanged="TitleIndexChanged">
      
                                <Items>
      
                                    <telerik:RadComboBoxItem Text="Todos" />
      
                                </Items>
      
                            </telerik:RadComboBox>
      
                            <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
      
      
      
                                <script type="text/javascript">
     
                                    function TitleIndexChanged(sender, args) {
     
                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
     
                                        tableView.filter("Supergrupo", args.get_item().get_value(), "EqualTo");
     
     
     
                                    }
      
                                </script>
      
                            </telerik:RadScriptBlock>
      
                        </FilterTemplate>
      
    <HeaderStyle Width="200px"></HeaderStyle>
      
                    </telerik:GridBoundColumn>
      
                    <telerik:GridBoundColumn UniqueName="Grupo" DataField="Grupo" HeaderText="Grupo" HeaderStyle-Width="200px">
      
                        <FilterTemplate>
      
                            <telerik:RadComboBox ID="RadComboBoxCity" DataSourceID="SqlDataSource3" DataTextField="Grupo" AutoPostBack="false"
      
                                DataValueField="Grupo" Height="100px" AppendDataBoundItems="true"
      
                                SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("Grupo").CurrentFilterValue %>'
      
                                runat="server" OnClientSelectedIndexChanged="CityIndexChanged">
      
                                <Items>
      
                                    <telerik:RadComboBoxItem Text="All" />
      
                                </Items>
      
                            </telerik:RadComboBox>
      
                            <telerik:RadScriptBlock ID="RadScriptBlock2" runat="server">
      
      
      
                                <script type="text/javascript">
     
                                    function CityIndexChanged(sender, args) {
     
                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
     
                                        tableView.filter("Grupo", args.get_item().get_value(), "EqualTo");
     
                                    }
      
                                </script>
      
      
      
                            </telerik:RadScriptBlock>
      
                        </FilterTemplate>
      
    <HeaderStyle Width="200px"></HeaderStyle>
      
                    </telerik:GridBoundColumn>
      
                </Columns>
      
    <EditFormSettings>
    <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
    </EditFormSettings>
      
            </MasterTableView>
      
    <FilterMenu EnableImageSprites="False"></FilterMenu>
      
        </telerik:RadGrid>
      
        <br />
      
        <telerik:RadToolTip ID="RadToolTip1" runat="server" OffsetY="3" Position="TopCenter"
      
            ShowCallout="false" Height="20px" ShowEvent="fromcode" />
      
        <asp:SqlDataSource ID="SqlDataSource1"
                ConnectionString="<%$ ConnectionStrings:BTIMEXICO_DESConnectionString %>" runat="server"
      
            SelectCommand="SELECT E.idEmpresa, E.Nombre AS Empresa, GE.idgrupo, G.Descripcion AS Grupo, SG.Descripcion AS SuperGrupo
      
                           FROM tbl_empresa E
      
                           LEFT JOIN tbl_grupoempresa GE
      
                           ON E.idEmpresa = GE.idEmpresa
      
                           LEFT JOIN tbl_grupos G
      
                           ON GE.idgrupo = G.idgrupo
     
                           LEFT JOIN tbl_Supergrupo SG
      
                           ON SG.idsupergrupo = G.idsupergrupo
      
                           ORDER BY Nombre">
      
        </asp:SqlDataSource>
      
        <asp:SqlDataSource ID="SqlDataSource2"
                ConnectionString="<%$ ConnectionStrings:BTIMEXICO_DESConnectionString %>" SelectCommand="SELECT DISTINCT a.Supergrupo FROM(Select Descripcion AS Supergrupo FROM tbl_supergrupo) AS a"
      
            runat="server">
      
        </asp:SqlDataSource>
      
        <asp:SqlDataSource ID="SqlDataSource3"
                ConnectionString="<%$ ConnectionStrings:BTIMEXICO_DESConnectionString %>" SelectCommand="SELECT DISTINCT a.Grupo FROM(Select Descripcion AS Grupo FROM tbl_grupos) AS a"
      
            runat="server">
      
        </asp:SqlDataSource>
     
        <div>
     
        </div>
        </form>
    </body>
    </html>
  14. James Campbell
    James Campbell avatar
    90 posts
    Member since:
    Jul 2012

    Posted 28 Mar 2012 Link to this post

    The code behind:

    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    using System.Data;
    using System.Configuration;
    using System.Web.Security;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Telerik.Web.UI;
     
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
     
        }
     
        protected void ImportedFilter_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
        {
     
            DataRowView rowView = (DataRowView)e.Item.DataItem;
     
            if (rowView["Bool"] is DBNull)
            {
     
                e.Item.Text = "No";
     
                e.Item.Value = "0";
     
            }
     
            else if ((bool)rowView["Bool"])
            {
     
                e.Item.Text = "Yes";
     
                e.Item.Value = "1";
     
            }
     
        }
     
     
     
        protected void RadGrid1_PreRender(object sender, System.EventArgs e)
        {
     
            if (RadGrid1.MasterTableView.FilterExpression != string.Empty)
            {
     
                RefreshCombos();
     
            }
     
        }
     
        protected void RefreshCombos()
        {
     
            if (RadGrid1.MasterTableView.FilterExpression.ToString().Contains("Supergrupo"))
            {
            SqlDataSource2.SelectCommand = SqlDataSource2.SelectCommand + " WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();
            }
            else
            {
            SqlDataSource3.SelectCommand = SqlDataSource3.SelectCommand + " WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();
            }
     
            RadGrid1.MasterTableView.Rebind(); //<<< Here is where the exception pops up
     
        }
        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.FilterCommandName)
            {
                Pair filterPair = (Pair)e.CommandArgument;
     
                switch (filterPair.Second.ToString())
                {
                    default:
                        break;
                }
            }
        }
     
    }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017