radgrid disappear data after filtering

2 posts, 0 answers
  1. raja
    raja avatar
    6 posts
    Member since:
    Jun 2014

    Posted 18 Oct Link to this post

    ASPX Page 

     <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
           <AjaxSettings>
               <telerik:AjaxSetting AjaxControlID="gvResourceActivity">
                   <UpdatedControls>
                       <telerik:AjaxUpdatedControl ControlID="gvResourceActivity" 
                           LoadingPanelID="RadAjaxLoadingPanel1" />
                   </UpdatedControls>
               </telerik:AjaxSetting>
           </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" MinDisplayTime="1000"
            Transparency="10" BackColor="#EFEFEF">
            <img alt="Loading..." src="../../Images/ajax-loader.gif" style="width: 100px; height: 100px;
                border: 0px;" />
            <p style="color: Blue;">
                Please wait! while your request is being processed.</p>
        </telerik:RadAjaxLoadingPanel>

    <telerik:RadGrid ID="gvResourceActivity" runat="server" 
                        AllowFilteringByColumn="True" AllowSorting="True" AllowPaging="True" PageSize="50"
                        AutoGenerateColumns="False" Height="600px" EnableLinqExpressions="false" 
                        Skin="Simple" onitemcommand="gvResourceActivity_ItemCommand" 
                            onitemcreated="gvResourceActivity_ItemCreated" 
                            onneeddatasource="gvResourceActivity_NeedDataSource">
                        <ClientSettings EnableRowHoverStyle="true">
                            <Scrolling UseStaticHeaders="true" AllowScroll="true" SaveScrollPosition="true" />
                            <Selecting AllowRowSelect="true" />
                        </ClientSettings>
                        <PagerStyle AlwaysVisible="true" />
                        <ExportSettings ExportOnlyData="true" FileName="ESR Detail List" IgnorePaging="true"
                            OpenInNewWindow="true" Excel-Format="ExcelML">
                        </ExportSettings>
                        <MasterTableView TableLayout="Fixed">
                            <Columns>
                                <telerik:GridBoundColumn UniqueName="BusinessUnitName" DataField="BusinessUnitName"
                                    HeaderText="Business Unit" HeaderStyle-Wrap="false" ItemStyle-Wrap="false">
                                    <FilterTemplate>
                                        <telerik:RadComboBox ID="rcmbBusinessUnit" runat="server" Filter="Contains" NoWrap="true"
                                            DropDownAutoWidth="Enabled" Height="200px" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("BusinessUnitName").CurrentFilterValue %>'
                                            OnClientSelectedIndexChanged="BUIndexChanged" Width="95%">
                                        </telerik:RadComboBox>
                                        <telerik:RadScriptBlock ID="radscriptBusinessUnitCombo" runat="server">
                                            <script type="text/javascript">
                                                function BUIndexChanged(sender, args) {
                                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                                    tableView.filter("BusinessUnitName", args.get_item().get_value(), "Contains");
                                                }
                                            </script>
                                        </telerik:RadScriptBlock>
                                    </FilterTemplate>
                                </telerik:GridBoundColumn>
                            </Columns>
                            <CommandItemStyle Height="40px" />
                            <ItemStyle HorizontalAlign="Left" />
                            <AlternatingItemStyle HorizontalAlign="Left" />
                            <HeaderStyle HorizontalAlign="Left" />
                        </MasterTableView>
                    </telerik:RadGrid>



    Code Page


        private string strBU_Id = null, strFromDate = "10-01-2015", strToDate = "09-30-2016", strWOID = null, strLIID = null, strTeamID = null, strUserID = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindResourceActivity();
                gvResourceActivity.DataBind();
            }
        }
        private void BindResourceActivity()
        {
            objProperties = new OMSDetailsProperties();
            if (!String.IsNullOrEmpty(strBU_Id))
                objProperties.iBusinessUnit = Convert.ToInt32(strBU_Id);
            else
                objProperties.iBusinessUnit = 0;

            if (!String.IsNullOrEmpty(strTeamID) && strTeamID != "0")
                objProperties.strTeamId = strTeamID;
            else
                objProperties.strTeamId = "";

            if (!String.IsNullOrEmpty(strUserID))
                objProperties.UserId = Convert.ToInt32(strUserID);
            else
                objProperties.UserId = 0;

            if (!string.IsNullOrEmpty(strFromDate))
                objProperties.DateFrom = strFromDate;
            else
                objProperties.DateFrom = "";

            if (!string.IsNullOrEmpty(strToDate))
                objProperties.DateTo = strToDate;
            else
                objProperties.DateTo = "";

            if (strWOID != string.Empty)
                objProperties.WorkOrderId = Convert.ToInt32(strWOID);
            else
                objProperties.WorkOrderId = 0;

            if (strLIID != string.Empty)
                objProperties.LineItemId = Convert.ToInt32(strLIID);
            else
                objProperties.LineItemId = 0;


            objWorkOrder = new WorkOrderBAL();
            DataTable dt = objWorkOrder.ReportResourceActivity(objProperties);


            gvResourceActivity.DataSource = dt;

        }
        
        protected void gvResourceActivity_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            BindResourceActivity();
        }
        protected void gvResourceActivity_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridFilteringItem)
            {
                GridFilteringItem filterItem = e.Item as GridFilteringItem;
                RadComboBox cmbBusinessUnit = filterItem.FindControl("rcmbBusinessUnit") as RadComboBox;

                BindBusinessUnit(cmbBusinessUnit);
            }

        }
        private void BindBusinessUnit(RadComboBox cmbBusinessUnit)
        {

            DataTable dtBusinessUnit = new DataTable();
            objWorkOrder = new WorkOrderBAL();
            objProperties = new OMSDetailsProperties();
            objProperties.RoleName = Session["Role"].ToString().Trim();
            objProperties.UserId = Convert.ToInt32(Session["UserId"].ToString().Trim());
            objProperties.WorkOrderType = "OE";
            objProperties.UserTypeId = Convert.ToInt32(Session["UserType"].ToString().Trim());
            dtBusinessUnit = objWorkOrder.GetBusinessUnitName(objProperties);
            DataRow dr = dtBusinessUnit.NewRow();
            dr[0] = 0;
            dr[1] = "All";
            dtBusinessUnit.Rows.InsertAt(dr, 0);
            cmbBusinessUnit.DataTextField = "BusinessUnitName";
            cmbBusinessUnit.DataValueField = "BusinessUnitId";
            cmbBusinessUnit.DataSource = dtBusinessUnit;
            cmbBusinessUnit.DataBind();
        }

        protected void gvResourceActivity_ItemCommand(object sender, GridCommandEventArgs e)
        {
            string gridMessage1 = null;

            if (e.CommandName == RadGrid.FilterCommandName)
            {
                Pair filterPair = (Pair)e.CommandArgument;

                gridMessage1 = "Current Filter function: '" + filterPair.First + "' for column '" + filterPair.Second + "'";

                switch (filterPair.Second.ToString())
                {
                    case "BusinessUnitName":
                        RadComboBox cmbBusinessUnit = (e.Item as GridFilteringItem)[filterPair.Second.ToString()].Controls[1] as RadComboBox;
                        strBU_Id = cmbBusinessUnit.SelectedItem.Value;
                        break;

                }


                gvResourceActivity.Rebind();
            }
        }
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 20 Oct Link to this post

    Hi,

    The grid should not disappear after filtering when it is populated through NeedDataSource. However, I noticed that you are also calling grid DataBind() inside PageLoad and this is most probably the reason for the problem you encounter, because mixing simple data binding with advanced data binding is not supported.

    Regards,
    Pavlina
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top