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

[Solved] SelectedIndexChanged Does not fire

9 Answers 344 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raj
Top achievements
Rank 1
Raj asked on 14 Jul 2009, 09:41 AM
Hi

I have created a checkbox filtering item using the method suggested in your link http://www.telerik.com/help/aspnet-ajax/grdfilteringforchecboxcolumn.html

As suggested I have followed the steps outlined below. However SelectedIndexChanged event never fires ?????
Here are the steps with associated code:
 
Please come back to me with sugguestions or anything I've missed

Regards
Raj  Patel

  1. Handle the ItemCreated event of the grid to modify the Controls collection of the corresponding header cell.

Here is the code

 protected void StockGrid_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {

        try
        {
                if (e.Item is GridFilteringItem)
                {
                    GridFilteringItem filteringItem = e.Item as GridFilteringItem;

                    (filteringItem[VwStockListMetadata.ColumnNames.StCode].Controls[0] as TextBox).Width = Unit.Percentage(100.0);
                    (filteringItem[VwStockListMetadata.ColumnNames.StDesc].Controls[0] as TextBox).Width = Unit.Percentage(100.0);
                    (filteringItem[VwStockListMetadata.ColumnNames.Location].Controls[0] as TextBox).Width = Unit.Percentage(100.0);
                    (filteringItem[VwStockListMetadata.ColumnNames.StBin].Controls[0] as TextBox).Width = Unit.Percentage(100.0);
                    (filteringItem[VwStockListMetadata.ColumnNames.StQuantity].Controls[0] as TextBox).Width = Unit.Percentage(100.0);
                    //(filteringItem[VwStockListMetadata.ColumnNames.StAutoReorder].Controls[0] as DropDownList).Width = Unit.Percentage(100.0);
                    (filteringItem[VwStockListMetadata.ColumnNames.StArchive].Controls[0] as TextBox).Width = Unit.Percentage(100.0);

                    //if (filteringItem["StAutoReorder"].Controls.Count == 0)
                    //{

                        filteringItem["StAutoReorder"].Controls.Clear();
                        DropDownList ddList = new DropDownList();
                        //ddList.ID = "yourID";
                        ddList.AutoPostBack = true;
                        ddList.SelectedIndexChanged += new System.EventHandler(ddList_SelectedIndexChanged);
                        ddList.Items.Add(new ListItem("Clear", "Empty"));
                        ddList.Items.Add(new ListItem("Checked", "True"));
                        ddList.Items.Add(new ListItem("Unchecked", "False"));
                        if (Session["ddlSelValue"] != null)
                        {
                            ddList.Items.FindByValue((string)Session["ddlSelValue"]).Selected = true;
                        }
                        filteringItem["StAutoReorder"].Controls.Add(ddList);
                        //ddSet = true;
                    //}
                }
        }
        catch (Exception ex)
        {
            IsError(ex);
        }
    }

 

  1. Handle the SelectedIndexChanged event of the drop-down list (which appears in the place of the textbox) to modify the grid FilterExpression so that it reflects the SelectedValue of the drop-down list you added.

protected void ddList_SelectedIndexChanged(object sender, System.EventArgs e)
{
 DropDownList ddList = (DropDownList)sender;
 Session["ddlSelValue"] = "True";

 ViewState[VwStockListMetadata.ColumnNames.StAutoReorder] = ddList.SelectedValue;
 StockGrid.MasterTableView.Rebind();
 switch (ddList.SelectedValue)
 {
     case "Empty":
         StockGrid.MasterTableView.FilterExpression = "([StAutoReorder] = 'N') ";
         foreach (GridColumn column in StockGrid.MasterTableView.Columns)
         {
             column.CurrentFilterFunction = GridKnownFunction.NoFilter;
             column.CurrentFilterValue = String.Empty;
         }
         StockGrid.MasterTableView.Rebind();
         break;
     case "True":
         StockGrid.MasterTableView.FilterExpression = "([StAutoReorder] = 'Y') ";
         foreach (GridColumn column in StockGrid.MasterTableView.Columns)
         {
             column.CurrentFilterFunction = GridKnownFunction.NoFilter;
             column.CurrentFilterValue = String.Empty;
         }
         StockGrid.MasterTableView.Rebind();
         break;
     case "False":
         StockGrid.MasterTableView.FilterExpression = String.Empty;
         foreach (GridColumn column in StockGrid.MasterTableView.Columns)
         {
             column.CurrentFilterFunction = GridKnownFunction.NoFilter;
             column.CurrentFilterValue = String.Empty;
         }
         StockGrid.MasterTableView.Rebind();
         break;
 }
}

 

In the NeedDataSource event handler, add the check box column's filter expression to the FilterExpression property of the table so that it is honored when the user triggers a filter action from another column. 
    protected void StockGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        PopulateGrid();
    }

    private void PopulateGrid()
    {
        try
        {
            //decimal stId = Convert.ToDecimal(ViewState[VwStockListMetadata.ColumnNames.StId]);
            string stockCode = null;
            string stockDesc = null;
            //decimal stLocId = Convert.ToDecimal(ViewState[VwStockListMetadata.ColumnNames.StLocId]);
            string location = null;
            string stBin = null;
            string stQuantity = null;
            bool bAutoReorder=false;
            string stArchive = null;

            if (StockGrid.MasterTableView.Items.Count != 0)
            {
                //--------------------------------
                //Get the filters entered to apply
                //--------------------------------
                GridFilteringItem item = StockGrid.MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem;
                stockCode = (item[VwStockListMetadata.ColumnNames.StCode].Controls[0] as TextBox).Text;
                stockDesc = (item[VwStockListMetadata.ColumnNames.StDesc].Controls[0] as TextBox).Text;
                location = (item[VwStockListMetadata.ColumnNames.Location].Controls[0] as TextBox).Text;
                stBin = (item[VwStockListMetadata.ColumnNames.StBin].Controls[0] as TextBox).Text;
                stQuantity = (item[VwStockListMetadata.ColumnNames.StQuantity].Controls[0] as TextBox).Text;

                if (Session["ddlSelValue"] != null)
                    if ((item[VwStockListMetadata.ColumnNames.StAutoReorder].Controls[0] as DropDownList).SelectedValue=="True")
                        bAutoReorder = true;
                    else
                        bAutoReorder = false;

                stArchive = (item[VwStockListMetadata.ColumnNames.StArchive].Controls[0] as TextBox).Text;
            }
            VwStockListCollection col = null;

            if (Cache["CollectionObject"] == null)
            {
                col = new VwStockListCollection();

                //List<string> LocationList = new List<string>();
                //    Hashtable htLocations = GetUserLocations();
                //    foreach (string key in htLocations.Keys)
                //    {
                //        LocationList.Add(key);
                //    }

                //    col.Query.Where(col.Query.Location.In(LocationList.ToArray()));
                col.Query.OrderBy(col.Query.StCode.Ascending);
                if (!col.Query.Load())
                {
                    string SqlText = col.Query.es.LastQuery;
                    StockGrid.DataSource = new Object[0];
                    return;
                }

                string SqlText2 = col.Query.es.LastQuery;
                Cache.Insert("CollectionObject", col, null, DateTime.MaxValue, TimeSpan.FromHours(2));
            }
            else
            {
                col = Cache["CollectionObject"] as VwStockListCollection;
            }

            //---------------------------------------------
            // Now apply the filters the user has selected
            //---------------------------------------------
            if (!string.IsNullOrEmpty(stockCode))
            {
                ViewState[VwStockListMetadata.ColumnNames.StCode] = stockCode;
                col.Filter = Helper.AndFilter(col.Filter, VwStockListMetadata.ColumnNames.StCode + " LIKE '%" + stockCode + "%'");
            }

            if (!string.IsNullOrEmpty(stockDesc))
            {
                ViewState[VwStockListMetadata.ColumnNames.StDesc] = stockDesc;
                col.Filter = Helper.AndFilter(col.Filter, VwStockListMetadata.ColumnNames.StDesc + " LIKE '%" + stockDesc + "%'");
            }

            if (!string.IsNullOrEmpty(location))
            {
                ViewState[VwStockListMetadata.ColumnNames.Location] = location;
                col.Filter = Helper.AndFilter(col.Filter, VwStockListMetadata.ColumnNames.Location + " LIKE '%" + location + "%'");
            }

            if (!string.IsNullOrEmpty(stBin))
            {
                ViewState[VwStockListMetadata.ColumnNames.StBin] = stBin;
                col.Filter = Helper.AndFilter(col.Filter, VwStockListMetadata.ColumnNames.StBin + " LIKE '%" + stBin + "%'");
            }

            if (!string.IsNullOrEmpty(stQuantity))
            {
                ViewState[VwStockListMetadata.ColumnNames.StQuantity] = stQuantity;
                col.Filter = Helper.AndFilter(col.Filter, VwStockListMetadata.ColumnNames.StQuantity + " = " + stQuantity );
            }

            if (Session["ddlSelValue"] != null)
            {
                if (bAutoReorder==true)
                    ViewState[VwStockListMetadata.ColumnNames.StAutoReorder] = "True";
                else
                    ViewState[VwStockListMetadata.ColumnNames.StAutoReorder] = "False";

                col.Filter = Helper.AndFilter(col.Filter, VwStockListMetadata.ColumnNames.StAutoReorder + " = " + bAutoReorder);
            }

            string sortExpression = Session["SortExpression"] == null ? string.Empty : (string)Session["SortExpression"];
            col.Sort = sortExpression;

            StockGrid.DataSource = col;
        }
        catch (Exception ex)
        {
            IsError(ex);
        }
    }


9 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 17 Jul 2009, 08:39 AM
Hello Raj,

Your implementation seems correct and the SelectedIndexChanged event should be fired as expected. I suppose you set a breakpoint in your handler to verify the abnormality.

Can you also confirm that the viewstate of the grid instance (or the page in which it resides) is enabled? I will appreciate if you post your grid definition in this thread as well to research the matter further and provide more to-the-point explanation/fix.

Regards,
Sebastian
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
Raj
Top achievements
Rank 1
answered on 19 Jul 2009, 02:46 PM
Hi Seb

Thanks for your response , as per request here is the page defintion which includes the defintion for the grid.

I look forward to here from you.

Raj 


<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="StockList.aspx.cs" Inherits="StockList" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register TagPrefix="uc1" TagName="ucError" Src="~/UserControls/UCError.ascx"  %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div style="padding-left:5px">
    <uc1:ucError ID="ucError" runat="server" Visible="false" />  
<table border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <asp:Button ID="btnApplyFilter" Visible="false" runat="server" Text="Apply Filter"
                onclick="btnApplyFilter_Click" />
        </td>
        <td>
            <asp:Button ID="btnClearFilter" runat="server" Text="ClearFilter"
                onclick="btnClearFilter_Click" />
        </td>
    </tr>
</table>
</div>
<div style="padding:5px;">
    <telerik:RadToolTipManager ID="RadToolTipManager1" runat="server"
        Position="BottomRight" AutoCloseDelay="4000">
    </telerik:RadToolTipManager>
    <telerik:RadAjaxManagerProxy ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="btnApplyFilter">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="StockGrid"
                    LoadingPanelID="RadAjaxLoadingPanel1"/>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="btnClearFilter">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="StockGrid"
                    LoadingPanelID="RadAjaxLoadingPanel1"/>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="StockGrid">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="StockGrid"
                    LoadingPanelID="RadAjaxLoadingPanel1"/>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManagerProxy>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"
            CssClass="LoadingPanel"
        Transparency="20" BackgroundPosition="Center">
        <table style="width:100%;height:100%;">
                <tr style="height:100%">
                    <td align="center" valign="middle" style="width:100%">
                        <img alt="Loading..." 
                            src="Img/ajax-loader.gif" style="border: 0px;" />  
                    </td>
                </tr>
          </table>        
        </telerik:RadAjaxLoadingPanel>
    <telerik:RadGrid ID="StockGrid" runat="server" EnableViewState="true" 
        AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True"
        GridLines="None" onitemcommand="StockGrid_ItemCommand"
        onprerender="StockGrid_PreRender"  EnableLinqExpressions="false"
        onitemdatabound="StockGrid_ItemDataBound"
        GroupingSettings-CaseSensitive="false"
        onpageindexchanged="StockGrid_PageIndexChanged"
        onneeddatasource="StockGrid_NeedDataSource" Skin="Web20" onitemcreated="StockGrid_ItemCreated"
        >
        <ClientSettings>
            <Selecting AllowRowSelect="true" />
            <ClientEvents OnRowDblClick="RowStockSelected" />
        </ClientSettings>
<MasterTableView EditMode="InPlace" AllowFilteringByColumn="true" ShowFooter="true" EnableColumnsViewState="true"
    AutoGenerateColumns="False" CellSpacing="-1" DataKeyNames="StId" Font-Size="90%"
            EnableViewState="False" Width="100%">           
            <PagerStyle Mode="NextPrevAndNumeric" Visible="true"  />
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
<ItemStyle Height="25px" />
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
    <Columns>
        <telerik:GridBoundColumn DataField="StId" UniqueName="StId" Display="false">
            <HeaderStyle HorizontalAlign="Center" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="StCode"
            HeaderText="Stock Code"
            UniqueName="StCode"
            SortExpression="StCode"
            AutoPostBackOnFilter="true"
            ShowFilterIcon="false"
            CurrentFilterFunction="Contains">
            <HeaderStyle HorizontalAlign="Center" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="StDesc"
            HeaderText="Stock Description"
            UniqueName="StDesc"
            SortExpression="StDesc"
            ShowFilterIcon="false"
            AutoPostBackOnFilter="true"
            CurrentFilterFunction="Contains">
            <HeaderStyle HorizontalAlign="Center" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Location"
            HeaderText="Location"
            UniqueName="Location"
            SortExpression="Location"
            ShowFilterIcon="false"
            AutoPostBackOnFilter="true"
            CurrentFilterFunction="Contains">
            <HeaderStyle HorizontalAlign="Center" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="StBin"
            HeaderText="Bin"
            UniqueName="StBin"
            SortExpression="StBin"
            ShowFilterIcon="false"
            AutoPostBackOnFilter="true"
            CurrentFilterFunction="Contains">
            <HeaderStyle HorizontalAlign="Center" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="StQuantity"
            HeaderText="Quantity"
            UniqueName="StQuantity"
            SortExpression="StQuantity"
            ShowFilterIcon="false"
            AutoPostBackOnFilter="true"
            CurrentFilterFunction="Contains">
            <HeaderStyle HorizontalAlign="Center" />
        </telerik:GridBoundColumn>
        <telerik:GridCheckBoxColumn DataField="StAutoReorder"
            HeaderText="ReOrder"
            UniqueName="StAutoReorder"
            SortExpression="StAutoReorder"
            ShowFilterIcon="false"
            AutoPostBackOnFilter="false"
            CurrentFilterFunction="Contains">           
            <HeaderStyle HorizontalAlign="Center" />
        </telerik:GridCheckBoxColumn>     
        <telerik:GridTemplateColumn DataField="StAutoReorder"
            HeaderText="ReOrder"
            UniqueName="StAutoReorder"
            SortExpression="StAutoReorder"
            ShowFilterIcon="false"
            AutoPostBackOnFilter="false"
            CurrentFilterFunction="Contains">           
            <HeaderStyle HorizontalAlign="Center" />
        </telerik:GridTemplateColumn>   
        <telerik:GridBoundColumn DataField="StArchive"
            HeaderText="Archived"
            UniqueName="StArchive"
            SortExpression="StArchive"
            AutoPostBackOnFilter="true"
            ShowFilterIcon="false"
            CurrentFilterFunction="Contains">
            <HeaderStyle HorizontalAlign="Center" />
        </telerik:GridBoundColumn>
    </Columns>
</MasterTableView>
    </telerik:RadGrid>   
</div>
</asp:Content>

 

0
Sebastian
Telerik team
answered on 20 Jul 2009, 10:15 AM

Hello Raj,

From your code snippets I see that you set EnableViewState = false for the MasterTableView - does setting this property back to true addresses the abnormality? Note that the grid viewstate has to be enabled in order to take advantage of features like grouping, filtering, etc.

You may also consider changing the id of the RadAjaxManagerProxy (RadAjaxManager1) to differentiate it from the RadAjaxManager instance which resides in your master page (in case it has the same id set).

Regards,

Sebastian
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
Raj
Top achievements
Rank 1
answered on 20 Jul 2009, 01:57 PM
Hi Seb

Thanks for you email. I changed to  EnableViewState to true and changed the name of the RadAjaxManagerProxy (RadAjaxManager1) to differentiate it from the RadAjaxManager instance which resides in your master page.

However no effect. Would welcome any other suggestions as this is becoming a show stopper.

Raj

0
Sebastian
Telerik team
answered on 23 Jul 2009, 01:32 PM
Hello Raj,

To progress in our investigation, I suggest you prepare a stripped working version of your project, exhibiting the abnormality, and send it enclosed to a regular support ticket. I will examine your complete code logic in detail and will get back to you with more info on the subject.

Best regards,
Sebastian
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
Jeffrey Gilliam
Top achievements
Rank 1
answered on 24 Oct 2009, 09:27 PM
Hello Telerik Team,

I am having what appears to be the same issue as Raj and am wondering if a solution was discovered.

I have created a stripped down version of the Grid Template Filtering example, basically just swapping out the data source on the page to a code-behind data source using Linq and taking out the header, footer and style classes. The grid will display the 10,000 + rows of data I'm now using just fine and the other default filters seems to work great. But, I'm currently stuck getting the drop-down style filter to work with the same issue as Raj - the selectedIndexChanged event is either not being fired or is not getting wired up correctly. Either way, the event method is not called, I've verified this in debug, and the filter does not work.

Any suggestions will be appreciated.

Jeff
0
Sebastian
Telerik team
answered on 26 Oct 2009, 11:03 AM
Hi Jeffrey,

Since Raj have not provided the requested sample, I would suggest you send a working subset of your project, illustrating the abnormality, attached to a standard support ticket. We will familiarize with your code implementation and will get around to you with our findings.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jeffrey Gilliam
Top achievements
Rank 1
answered on 26 Oct 2009, 01:08 PM

Greetings,

Thanks for the quick response. I eventually did figure out my issue, which was that I was calling DataBind() on my RadGrid after setting the DataSource(). I now know that this is not necessary and that it will cause strange behavior with filters. On to my next lesson to learn.

 

Thanks again,

 

Jeff

0
Raj
Top achievements
Rank 1
answered on 27 Oct 2009, 01:48 PM
Hi

Sorry I thought I'd sent as much of the project as I could. Anyway I recently revisited the project where I encountered this problem and managed to fix the problem by bind to a Csla Datasource control rather than Entity Spaces collection. 

My form requires 2 checkbox colunms first checkbox colunms works as expected however when I tested it with the second I get the following error messge 

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Cannot have multiple items selected in a DropDownList.

I have implemented both columns in the way suggested in  http://www.telerik.com/help/aspnet-ajax/grdfilteringforchecboxcolumn.html

Regards
Raj
Tags
Grid
Asked by
Raj
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Raj
Top achievements
Rank 1
Jeffrey Gilliam
Top achievements
Rank 1
Share this question
or