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

Rebind a grid that contains GroupByExpressions fails

2 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joel Richman
Top achievements
Rank 1
Joel Richman asked on 28 Jul 2012, 12:09 AM
Hello Everyone,

I have a RadGrid that uses GroupByExpressions.  I'm setting the datasource via the NeedDataSource event.  On the initial load everything loads fine and the data is displayed as expected.  Any postback that causes the data to refresh via the .Rebind() method causes the grid to lose all data.  When I remove the GroupByExpressions from the markup the grid works as expected.  I've created a simplified version with the markup and code necessary to reproduce.  We're running version 2011.3.1305.40.  Does anyone have any ideas on how to fix this?  Thanks.

Here is the markup:
<telerik:RadScriptManager runat="server" ID="ScriptManager1"></telerik:RadScriptManager>
 
 <telerik:RadGrid runat="server" ID="grdServices" AutoGenerateColumns="false"
     Width="300px" Height="650px"
     onneeddatasource="grdServices_NeedDataSource"
     onselectedindexchanged="grdServices_SelectedIndexChanged" >
     <MasterTableView DataKeyNames="ServiceId" NoMasterRecordsText="" NoDetailRecordsText="" Width="100%" TableLayout="Fixed" GridLines="None">
 
         <GroupByExpressions>
             <telerik:GridGroupByExpression>
                 <GroupByFields>
                     <telerik:GridGroupByField FieldName="ServiceType" FieldAlias="Type"  />
                 </GroupByFields>
             </telerik:GridGroupByExpression>
         </GroupByExpressions>
 
         <Columns>
             <telerik:GridBoundColumn DataField="ServiceId" Visible="false"></telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="ServiceType" Visible="false" ></telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="Name" HeaderText="Service" ItemStyle-Wrap="false" ></telerik:GridBoundColumn>
         </Columns>       
     </MasterTableView>
     <ClientSettings Selecting-AllowRowSelect="true" EnableRowHoverStyle="true" EnablePostBackOnRowClick="true" AllowGroupExpandCollapse="false" AllowDragToGroup="false">
         <Scrolling AllowScroll="true" UseStaticHeaders="true" />
     </ClientSettings>
 </telerik:RadGrid>
 
 <asp:Button ID="btnRefresh" runat="server" onclick="btnRefresh_Click" Text="Refresh" />

Here is the code behind:
protected void Page_Load(object sender, EventArgs e)
{
 
}
protected void grdServices_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    List<Service> Services = new List<Service>();
    Services.Add(new Service() { ServiceId = 1, ServiceType = "My Service", Name = "srv 1" });
    Services.Add(new Service() { ServiceId = 1, ServiceType = "My Service", Name = "srv 2" });
    Services.Add(new Service() { ServiceId = 1, ServiceType = "My Service", Name = "srv 3" });
 
    Services.Add(new Service() { ServiceId = 1, ServiceType = "Your Service", Name = "srv 4" });
    Services.Add(new Service() { ServiceId = 1, ServiceType = "Your Service", Name = "srv 5" });
    Services.Add(new Service() { ServiceId = 1, ServiceType = "Your Service", Name = "srv 6" });
 
    grdServices.DataSource = Services;
}
 
protected void grdServices_SelectedIndexChanged(object sender, EventArgs e)
{
 
}
 
protected void btnRefresh_Click(object sender, EventArgs e)
{
    grdServices.Rebind();
}
 
public class Service
{
    public int ServiceId { get; set; }
    public string ServiceType { get; set; }
    public string Name { get; set; }
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 30 Jul 2012, 05:32 AM
Hi Joel,

Make sure that you are adding the SelectFields collection which determines the information that is displayed in the group header.
aspx:
<GroupByExpressions>
  <telerik:GridGroupByExpression>
    <SelectFields>
      <telerik:GridGroupByField FieldName="ServiceType" />
    </SelectFields>
    <GroupByFields>
       <telerik:GridGroupByField FieldName="ServiceType" FieldAlias="Type"  />
    </GroupByFields>
 </telerik:GridGroupByExpression>
</GroupByExpressions>
Also check the following help documentation which explains more about this.
Declarative Definition.

Thanks,
Princy.
0
Joel Richman
Top achievements
Rank 1
answered on 30 Jul 2012, 04:20 PM
Thanks Princy.  That solved it.

Joel
Tags
Grid
Asked by
Joel Richman
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Joel Richman
Top achievements
Rank 1
Share this question
or