radgrid disappear after filtering and sorting

5 posts, 0 answers
  1. Joe
    Joe avatar
    57 posts
    Member since:
    Mar 2013

    Posted 29 Jan 2014 Link to this post

    user will select date and other option (by radcombobbox) and then click "Search" button to show the result in radgrid.but user input text for filter or click the header to sort, the grid will disappear.

    user need to click the "Search" button again to show the result. how can i solve it ? thanks.

    the code as follows:


    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="false" PageSize="300" AllowMultiRowSelection="true"
    CssClass="radgrid" AllowFilteringByColumn="true" AutoGenerateColumns="false"
    GridLines="None" CellSpacing="0" Visible="true" EnableLinqExpressions="false">
    <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="false">
    <Selecting AllowRowSelect="True" />
    </ClientSettings>
    <MasterTableView DataKeyNames="id">

    <Columns>

    <telerik:GridTemplateColumn UniqueName="RowNo" HeaderText="No." AllowFiltering="false">
    <ItemTemplate>
    <%# (Container.ItemIndex+1).ToString() %>
    </ItemTemplate>
    <HeaderStyle Width="30px" />
    </telerik:GridTemplateColumn>

    <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" Visible="true" >
    </telerik:GridClientSelectColumn>

    <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" HeaderStyle-Width="50" ItemStyle-ForeColor="Blue" Visible="true">
    </telerik:GridEditCommandColumn>

    <telerik:GridBoundColumn DataField="DisplayName" ShowFilterIcon="true" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"
    FilterControlAltText="Filter DisplayName column" HeaderText="DisplayName"
    SortExpression="DisplayName" UniqueName="DisplayName" >
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="Job_Title" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="true"
    FilterControlAltText="Filter Job_Title column" HeaderText="Job_Title"
    SortExpression="Job_Title" UniqueName="Job_Title">
    </telerik:GridBoundColumn>

    XXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXX

    </Columns>
    </mastertableview>
    <FilterMenu EnableImageSprites="False"></FilterMenu>
    </telerik:RadGrid>

    Code behind as follows:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Server.ScriptTimeout = 1200

    End Sub


    Protected Sub btn_Search_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_Search.Click

    LoadSearchResult()

    End Sub


    Private Sub LoadSearchResult()

    Dim dc As New dcDataContext

    'get level3 of radcombobox
    Dim strCOM_cmb As String = ""

    For i = 0 To df_location_lv3.CheckedItems.Count - 1
    If df_location_lv3.CheckedItems(i).Checked = True Then
    strCOM_cmb += df_location_lv3.CheckedItems(i).Value.ToString & ","
    End If
    Next
    If Left(strCOM_cmb, 1) = "," Then
    strCOM_cmb = Right(strCOM_cmb, Len(strCOM_cmb) - 1)
    End If
    If Right(strCOM_cmb, 1) = "," Then
    strCOM_cmb = Left(strCOM_cmb, Len(strCOM_cmb) - 1)
    End If
    strCOM_cmb = TrimList(strCOM_cmb)

    Dim listCOM_cmb = Split(strCOM_cmb, ",")


    Dim txt_name_from As String = "A"
    Dim txt_name_to As String = "Z"

    If txt_displayname_start_from.Text <> String.Empty Then
    txt_name_from = txt_displayname_start_from.Text.ToLower.Trim
    End If

    If txt_displayname_start_to.Text <> String.Empty Then
    txt_name_to = txt_displayname_start_to.Text.ToLower.Trim
    End If


    Dim rec = (From a In dc.TmpDB_LMS _
    Where a.EmailDate Is Nothing _
    And a.Level2Desc = df_location_lv2.SelectedValue _
    And listCOM_cmb.Contains(a.Level3Desc) _
    And a.StartDate = CType(df_start_date.SelectedValue, Date) _
    And a.DisplayName.ToLower().Substring(0, txt_name_from.Length).CompareTo(txt_name_from.ToLower()) >= 0 AndAlso a.DisplayName.ToLower().Substring(0, txt_name_to.Length).CompareTo(txt_name_to.ToLower()) <= 0 _
    Order By a.DisplayName _
    ).ToList


    RadGrid1.DataSource = Nothing
    RadGrid1.DataSource = rec
    RadGrid1.DataBind()

    End Sub


  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 29 Jan 2014 in reply to Joe Link to this post

    Hi Joe,

    For operations like filtering, sorting, paging etc RadGrid should be bound using the NeedDataSource event. In case you dont want the grid to be shown initially, you can set its visibility as false. On the Button click for search you can simply call Rebind() to bind the grid to appropriate search, code the NeedDataSource event accordingly. Please try and let me know if any concern.

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joe
    Joe avatar
    57 posts
    Member since:
    Mar 2013

    Posted 03 Feb 2014 Link to this post

    Thx for your suggestion.
    it works that the grid will not disappear.

    but the filter function not works now.
    i enter keywords in filter textbox, but the radgrid show all data, not the data based on keywords.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Feb 2014 in reply to Joe Link to this post

    Hi Joe,

    I'm not able to replicate the issue, here is a sample code snippet please have a look and check the difference with your code:

    ASPX:
    <telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource" AllowFilteringByColumn="true" EnableLinqExpressions="false">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="CustomerID" UniqueName="CustomerID" ShowFilterIcon="true"AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" FilterControlAltText="Filter CustomerID column"HeaderText="CustomerID" SortExpression="CustomerID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CompanyName" UniqueName="CompanyName" ShowFilterIcon="true"AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" FilterControlAltText="Filter CompanyName column"HeaderText="CompanyName" SortExpression="CompanyName">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    VB:
    Protected Sub RadGrid1_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
        Dim ConnString As [String] = ConfigurationManager.ConnectionStrings("Northwind_newConnectionString3").ConnectionString
        Dim conn As New SqlConnection(ConnString)
        Dim adapter As New SqlDataAdapter()
        adapter.SelectCommand = New SqlCommand("SELECT CustomerID, CompanyName FROM Customers", conn)
        Dim myDataTable As New DataTable()
        conn.Open()
        Try
            adapter.Fill(myDataTable)
        Finally
            conn.Close()
        End Try
        RadGrid1.DataSource = myDataTable
    End Sub

    Thanks,
    Princy
  6. raja
    raja avatar
    6 posts
    Member since:
    Jun 2014

    Posted 18 Oct Link to this post

    Hi Princy

    I have added the NeedDataSource event but the grid is working perfectly for paging but not filtering. Find the code below and let me know corrections

    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();
            }
        }

     

     

     

     

    Thanks 

    Raja

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017