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

[Solved] Grid not binding after filtering

1 Answer 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam Steckel
Top achievements
Rank 1
Adam Steckel asked on 07 Jul 2014, 02:19 PM
Hi.

I'm noticing something weird happening with a telerik grid.  Short version is that when I filter it, I'm seeing an error that indicates there are no rows to display, despite me being able to see in the code that there is data there...

I have filter controls outside of the grid, it's a big page so I was trying to simplify it for my users

my drop down looks like this, it is databound in the code behind

<telerik:RadComboBox ID="ddlCompany" runat="server" Visible="False" AutoPostBack="True" DataValueField="CompanyID"
                       DataTextField="Name" OnSelectedIndexChanged="ddlCompany_SelectedIndexChanged" >
                       <Items>
                       </Items>
                   </telerik:RadComboBox>

my grid looks like this 

    <telerik:RadGrid ID="productionSearchResults" runat="server" AutoGenerateColumns="false" CellPadding="0" Skin="Windows7" EnableLinqExpressions="false" Width="100%"
                AllowPaging="true" AllowSorting="true" AllowFilteringByColumn="true" GridLines="None" PageSize="100" OnItemDataBound="productionSearchResults_ItemDataBound"
                AllowCustomPaging="true">
                <HeaderContextMenu EnableAutoScroll="True" />
                <HeaderStyle Font-Names="Verdana" />
                <AlternatingItemStyle Font-Names="Verdana" />
                <ItemStyle Font-Names="Verdana" />
                <PagerStyle AlwaysVisible="True" />
                <GroupingSettings CaseSensitive="false" />
                <ClientSettings>
                    <ClientEvents OnGridCreated="SizeGridToVerticalContent" />
                    <Scrolling UseStaticHeaders="true" AllowScroll="true" FrozenColumnsCount="0" />
                </ClientSettings>
 
                <MasterTableView CommandItemDisplay="Top" Width="98%">
                    <CommandItemSettings
                        ShowAddNewRecordButton="false" ShowRefreshButton="false"
                        ShowExportToWordButton="true" ExportToWordText="Export results to Word"
                        ShowExportToExcelButton="true" ExportToExcelText="Export results to Excel"
                        ShowExportToCsvButton="false" ExportToCsvText="Export results to CSV"
                        ShowExportToPdfButton="false" ExportToPdfText="Export results to PDF" />
 
                    <Columns>
                        <telerik:GridBoundColumn Visible="False" DataField="SessionID" HeaderText="SID" UniqueName="SessionID" AllowFiltering="false"  AllowSorting="false" >
                            <HeaderStyle BackColor="#E3E9DC"></HeaderStyle>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn Visible="False" DataField="Company" HeaderText="Company" UniqueName="Company" AllowFiltering="false"   AllowSorting="false"  >
                            <HeaderStyle BackColor="#E3E9DC"></HeaderStyle>
                        </telerik:GridBoundColumn>
<!-- other columns go here -->
  <telerik:GridTemplateColumn HeaderText="Ship List"  AllowFiltering="false" UniqueName="ShipList"   >
                            <HeaderStyle BackColor="#F2EDB7"></HeaderStyle>
                        </telerik:GridTemplateColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>


when the user selects a value in the list the following is called

Protected Sub ddlCompany_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs) Handles ddlCompany.SelectedIndexChanged
      Dim ddl As RadComboBox = CType(sender, RadComboBox)
 
      ddl.Items.FindItemByValue(e.Value).Selected = True
      CompanyID = CInt(e.Value)
      Dim filterExpression As String
      filterExpression = "([Company]='" + e.Value + "')"
      productionSearchResults.MasterTableView.FilterExpression = filterExpression
      productionSearchResults.Rebind()
  End Sub

this should go away and call the need data source function (which it does) then rebind the grid with the filtered data set.  But when it gets to the rebinding, I'm not seeing any data items, just filter items.... I can clearly see that there is data there, it just doesn't bind.

here's the need data source function
Private Sub productionSearchResults_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles productionSearchResults.NeedDataSource
 
      pageIndex = productionSearchResults.CurrentPageIndex
      Controller.Page(Me)
      productionSearchResults.DataSource = Productions
      productionSearchResults.MasterTableView.VirtualItemCount = totalCount
      productionSearchResults.VirtualItemCount = totalCount
  End Sub

and my item databound

Protected Sub productionSearchResults_ItemDataBound(sender As Object, e As GridItemEventArgs)
      Dim sImgX As String
      Dim sImgCheck As String
 
      sImgX = ResolveUrl("~/images/x.gif")
      sImgCheck = ResolveUrl("~/images/check.gif")
 
 
      If TypeOf e.Item Is GridDataItem Then
 
          Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
 
          If dataItem("ProductionNotes").Text.Contains("NEEDS REVIEW") Then
              e.Item.BackColor = Color.Pink
          End If
          dataItem("SessionID").Text = String.Format("<a href=""{0}"">{1}</a>", _
                                       BuildPageUrl("production/ProductionList.aspx", NavLevel.Session, Integer.Parse(dataItem("SessionID").Text)), dataItem("SessionID").Text)
 
          If Len(PMSession.SID) = 0 Then
              dataItem("shipList").Text = String.Format("<a href=""{0}?ProductionID={1}"" target=_Blank><img src=""{2}"" border=0></a>", _
                                                         BuildPageUrl("reports/Session/SessionShipList.aspx", NavLevel.Session, iSID), ProductionID _
                                                         , ResolveUrl("~/images/report2.gif"))
 
          Else
              dataItem("ProductionID").Text = String.Format("<a href=""{0}?id={1}&cmd=2"">{2}</a>", BuildPageUrl("production/ProductionDetail.aspx"), dataItem("ProductionID"), iSID)
              dataItem("shipList").Text = String.Format("<a href=""{0}?ProductionID={1}"" target=_Blank><img src=""{2}"" border=0></a>", _
                                                         BuildPageUrl("reports/Session/SessionShipList.aspx"), ProductionID, ResolveUrl("~/images/report2.gif"))
          End If
 
 
      Else
      End If

any ideas?

1 Answer, 1 is accepted

Sort by
0
Adam Steckel
Top achievements
Rank 1
answered on 09 Jul 2014, 09:12 AM
Problem solved thanks to stack overflow 

Need to make sure that the filter expression is empty before setting the data source of my grid
Tags
Grid
Asked by
Adam Steckel
Top achievements
Rank 1
Answers by
Adam Steckel
Top achievements
Rank 1
Share this question
or