Grid data does not display after rebind()

3 posts, 1 answers
  1. Pete
    Pete avatar
    14 posts
    Member since:
    Jun 2010

    Posted 16 Dec 2010 Link to this post

    Hello,
    I'm attempting to perform server side filtering on a RadGrid.  I'm trying to follow your examples on filtering as well as some blog posts found here and here.  On intial page load I load the Grid using a SQL data set. This loads fine.  I then load filters for the status column of "All, Active, and Working".  These values match exactly to what is returned in the data. When I click on the filter for the status column the server side event is called but the data is removed from the grid. 
    Can you tell me what I'm doing wrong?
    thanks
    pete

    ASPX
    <rad:RadGrid id="RadGrid1" 
     OnItemCreated="RadGrid1_ItemCreated" 
     OnPreRender="RadGrid1_PreRender" 
     OnItemCommand="RadGrid1_ItemCommand"                                 
     ShowStatusBar="true" runat="server" AllowPaging="False" AllowSorting="True"
     AllowMultiRowSelection="True" AutoGenerateColumns="false"  
     ClientSettings-Resizing-ResizeGridOnColumnResize="false" 
     EnablePostBackOnRowClick="true"
     Width="100%"   Height="92%"  Skin="Windows7" AllowFilteringByColumn="true" EnableLinqExpressions="false">
            <MasterTableView PageSize="10" Width="100%" TableLayout="Fixed" EnableViewState="false">
                  <Columns>                        
                        <rad:GridTemplateColumn UniqueName="CheckBoxTemplateColumn"  
                                               HeaderStyle-Width="10%" 
                                               HeaderStyle-HorizontalAlign="Center" 
                                               AllowFiltering="false">
                                                   <HeaderTemplate>
                                                    <asp:CheckBox id="headerChkbox" Text="Select All" OnCheckedChanged="ToggleSelectedState" AutoPostBack="True" runat="server"></asp:CheckBox>
                                                   </HeaderTemplate>
                                                   <ItemTemplate >
                                                       <asp:CheckBox id="CheckBox1" OnCheckedChanged="ToggleRowSelection" AutoPostBack="True" runat="server" Width="65"></asp:CheckBox>
                                                   </ItemTemplate>                                            </rad:GridTemplateColumn>                                                         <rad:GridBoundColumn 
                                                   DataField="DISCUSSION" 
                                                   DataType="System.String" 
                                                   HeaderText="Discussion"    
                                                   Visible="False"                                                   
                                                   UniqueName="DISCUSSION">
                                                   <ItemStyle />
                                               </rad:GridBoundColumn>                        
                                               <rad:GridBoundColumn 
                                                   DataField="KEY" 
                                                   DataType="System.String" 
                                                   HeaderText="ID"                                                 Visible="True"                                                   
                                                   UniqueName="KEY"
                                                     
                                                   HeaderStyle-HorizontalAlign="Center" 
                                                   ItemStyle-HorizontalAlign="Center" 
                                                   AllowFiltering="false">
                                                   <ItemStyle />
                                               </rad:GridBoundColumn>
                                               <rad:GridBoundColumn 
                                                   DataField="NAME" 
                                                   DataType="System.String" 
                                                   HeaderText="Name"                                                       
                                                   UniqueName="NAME" 
                                                   HeaderStyle-HorizontalAlign="Center" 
                                                   ItemStyle-HorizontalAlign="Center" 
                                                   HeaderStyle-Width="40%" 
                                                   AllowFiltering="false">
                                                   <ItemStyle />
                                               </rad:GridBoundColumn>
                                                                                           <rad:GridBoundColumn 
                                                   DataField="STATUS" 
                                                   DataType="System.String" 
                                                   HeaderText="Status"                                                       
                                                   UniqueName="STATUS"                                               
                                                   SortExpression="STATUS"                                                
                                                   ShowSortIcon="true"  
                                                   HeaderStyle-HorizontalAlign="Center" 
                                                   ItemStyle-HorizontalAlign="Center" 
                                                   HeaderStyle-Width="10%" 
                                                   AllowFiltering="true"
                                                   AutoPostBackOnFilter="true" >
                                                   <ItemStyle />
                                                   <FilterTemplate>                                                    
                                                       <rad:RadComboBox ID="RadComboBoxStatus"  OnSelectedIndexChanged="FilterCombo_SelectedIndexChanged" 
                                                           DataTextField="STATUS" 
                                                           AutoPostBack="true"
                                                           DataValueField="STATUS" Width="70px"                                                          
                                                           runat="server" 
                                                           AppendDataBoundItems="true">                                                         <Items>                                                             <rad:RadComboBoxItem Text="All"  Value="All" /> 
                                                               <rad:RadComboBoxItem Text="Active"  Value="Active"/> 
                                                               <rad:RadComboBoxItem Text="Working" Value="Working" />  
                                                                                     
                                                           </Items>
                                                       </rad:RadComboBox>                                                   
                                                   </FilterTemplate>
                                               </rad:GridBoundColumn>
                                                                                                                                                                              </Columns>
                                       </MasterTableView>
                                       <ClientSettings EnableRowHoverStyle="true" 
                                                       Resizing-AllowColumnResize="true"
                                                       Resizing-AllowRowResize="true"  
                                                       Resizing-EnableRealTimeResize ="false" 
                                                       Resizing-ResizeGridOnColumnResize="false" 
                                                       Resizing-ClipCellContentOnResize ="false">                                                    
                                           <Scrolling AllowScroll ="true" UseStaticHeaders="true" />
                                           <ClientEvents OnColumnResized="OnColumnResized" />                                        
                                       </ClientSettings>
                                       <PagerStyle Mode="Slider"></PagerStyle>
                                   </rad:RadGrid>

    CS
    protected void FilterCombo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
        {
            string filterExpression;
            filterExpression = "([STATUS] = \'" + e.Text + "\')";
            RadGrid1.MasterTableView.FilterExpression = filterExpression;
            RadGrid1.MasterTableView.Rebind();
        }
  2. Answer
    Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 16 Dec 2010 Link to this post

    Hello Pete,

    If you don't handle the OnNeedDataSource event, you can't call Rebind because it doesn't know what it's rebinding to. So you need to handle that event and pass it the DataSet you're using.

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Pete
    Pete avatar
    14 posts
    Member since:
    Jun 2010

    Posted 17 Dec 2010 Link to this post

    Hello Cori,
    I added the OnNeedDataSource event and at first it didn't work (wasn't calling the radcombo box selection change).  I remembered the view state and set that to true (EnableViewState=true).
    Seems to be working now.
    Thanks!
    Pete
Back to Top